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?

<?php
  //grab date
	$time = date("dmy");
	
  	$directory="pages/events";
  // create a handler to the directory
    $dirhandler = opendir($directory);
 
  // read all the files from directory
    $nofiles=0;
    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)
        {
			$nofiles++;
			$files[$nofiles]=$file;
        }   
    	}
		  //arange by date			
			sort($files,SORT_NUMERIC);
			//print_r($files);
		

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

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

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]));

...to...

$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, networking, learning, and sharing knowledge.