KresentPhresh Posted August 4, 2009 Share Posted August 4, 2009 Alright... So I'm still working with the same old array set I posted about a few days ago. (If you're unaware, I'm querying a database table with two fields - Timestamps and ID, and returning all timestamps that match a certain ID, so what I end up with is an array of ##-##-#### ##:##:## timestamps in DATETIME format.) The problem I had before was grouping the results into an array by date where the date was the key and the number of rows matching that date were the values so I could parse something like; 4 Clicks on 07/29/2009 5 Clicks on 07/30/2009 Etc. This is working correctly, but now for the purpose of graphing the data, I need to be able to check something first. Basically, I just need to figure out how to check EVERY key in the array to see if they're all identical (that way if ALL the dates are the same, I can make a different graph that charts them on a 24-hour timeline) but I'm not really sure how I would go about handling such an operation. If anyone has any expertise they could lend, it would be much appreciated. Many thanks. -R Link to comment https://forums.phpfreaks.com/topic/168850-solved-comparing-array-keys/ Share on other sites More sharing options...
MatthewJ Posted August 4, 2009 Share Posted August 4, 2009 <?php #Just use array_keys on the array... if it has a sizeof() > 1 there are different keys $arr1 = array('key1'=>'Val1','key1'=>'Val1','key3'=>'Val1','key1'=>'Val1','key2'=>'Val1'); $test = array_keys($arr1); echo "The array has ".sizeof($test)." array keys"; echo "<br />"; $arr2 = array('key1'=>'Val1','key1'=>'Val1','key1'=>'Val1','key1'=>'Val1','key1'=>'Val1'); $test2 = array_keys($arr2); echo "The array has ".sizeof($test2)." array keys"; ?> Link to comment https://forums.phpfreaks.com/topic/168850-solved-comparing-array-keys/#findComment-890907 Share on other sites More sharing options...
KresentPhresh Posted August 4, 2009 Author Share Posted August 4, 2009 <?php #Just use array_keys on the array... if it has a sizeof() > 1 there are different keys $arr1 = array('key1'=>'Val1','key1'=>'Val1','key3'=>'Val1','key1'=>'Val1','key2'=>'Val1'); $test = array_keys($arr1); echo "The array has ".sizeof($test)." array keys"; echo "<br />"; $arr2 = array('key1'=>'Val1','key1'=>'Val1','key1'=>'Val1','key1'=>'Val1','key1'=>'Val1'); $test2 = array_keys($arr2); echo "The array has ".sizeof($test2)." array keys"; ?> Ahhhhh, yes! I was looking at that function but wasn't sure if it would do what I needed, but yeah, checking the size of the result.... PERFECT! You rule, sir! Link to comment https://forums.phpfreaks.com/topic/168850-solved-comparing-array-keys/#findComment-890926 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.