Jump to content

[SOLVED] Get the key of highest value in an associative array


sKunKbad

Recommended Posts

Actually, it wasn't solved, but I did solve it. I'm working on a google sitemap generator for the Kohana php framework. You can see in the code below that I am checking the last modified time of all controller and view files associated with a "page", then I compare those times and output the sitemap with the most recent last modified time for each "page".

 

There's still a lot of work to do...

 

header("Content-Type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd\">";
$pages = array(
			'welcome' => array('views/welcome_content.php','controllers/welcome.php'),
			'second' => array('views/second_content.php','controllers/second.php')
			);
foreach ($pages as $page => $parts){ 
for($x=0;$x<=count($parts)-1;$x++){
	$filename = "C:/wamp/www/kohana/application/$parts[$x]";
	$timecheck[] = filemtime($filename);
}
$largest = max($timecheck);
$large = array_keys($timecheck, $largest);
$filemtimeHome = date ("c", $timecheck["$large[0]"]);
echo "
<url>
	<loc>" . url::site("$page", 'http') . ".php</loc>
	<lastmod>$filemtimeHome</lastmod>
</url>";
unset($timecheck);
}
echo"</urlset>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.