Jump to content

Recommended Posts

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

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

?>

<?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!

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.