Im new to php and have been struggling with this for some time, but I expect its something simple.

Basically I have some code below which I want to use to display an events board.
-Info for each event comes from a separate xml file for each event.
-XML files are named by date, ie today would be 050611.xml (DD/MM/YY)
-Load all XML files in a directory and display items by tag name automatically.

As it is my code works fine. It finds all files in the directory that = more than today date and adds them to an array.

Then an array element can be used to load the corresponding xml (see red) and show the result.

Now here is my problem, I need it to be able to repeat the process (see green) for each item in the array automatically even if the number of elements in the array changes.

...Perhaps some kind of wild card for $files[0] so that it repeats for all the array elements?

  //grab date
	$time = date("dmy");
  // create a handler to the directory
    $dirhandler = opendir($directory);
  // read all the files from directory
    while ($file = readdir($dirhandler)) {
      // if $file isn't this directory or its parent and is more than now 
      //add to the $files array
        if ($file != '.' && $file != '..' && $file >= $time-3600)
		  //arange by date			

  //grab file name from $files array and set xml location. then load.
  //$grab = ($files[0]);
	$source = ("pages/events/".($files[0]));
	$xmlDoc = new DOMDocument();

		//shows specific node data
			$x=$xmlDoc->getElementsByTagName( "_event_date" );
			$y=$xmlDoc->getElementsByTagName( "_event_title" );
			$z=$xmlDoc->getElementsByTagName( "_event_desc" );
	echo "<br/>";
	echo $x;
	echo "<br/>";
	echo "<br/>";
	echo $y;
	echo "<br/>";
	echo "<br/>";
	echo $z;
  //close the handler

Any help at all would be greatly appreciated, but please be patient I am learning! :)

Aha after all that, I've managed to figure something out!

If anyone wants to know, just add:

foreach($files as $key=>$value) { }

...and change...

$source = ("pages/events/".($files[0]));

$source = ("pages/events/".($value));

I love it when a plan comes together!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.