Jump to content

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


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>";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.