Is there any easy way to get the hightest numeric value of an associative array?
$array = array(
0 => array(
'key1' => '123',
'key2' => 'values we',
'key3' => 'do not',
'key4' => 'care about'
),
1 => array(
'key1' => '124',
'key2' => 'values we',
'key3' => 'do not',
'key4' => 'care about'
),
2 => array(
'key1' => '125',
'key2' => 'values we',
'key3' => 'do not',
'key4' => 'care about'
)
);
AwesomeFunction($array, 'key1'); // returns 2 ($array key)
Please be kind since this question was written with a phone. Thanks.
For example, the following statement defines an associative array a with key signature [ int, string ] and stores the integer value 456 in a location named by the tuple [ 123, "hello" ]: a[123, "hello"] = 456; The type of each object contained in the array is also fixed for all elements in a given array.
If count(filtered_array) == count(original_array), then it is an assoc array. If count(filtered_array) == 0, then it is an indexed array.
There is no max on the limit of an array. There is a limit on the amount of memory your script can use. This can be changed in the 'memory_limit' in your php.
PHP 5.5 introduced array_column()
which makes this much simpler:
echo max(array_column($array, 'key1'));
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With