22.1 C
New York
Friday, August 19, 2022

How to get maximum key value of array in PHP?

- Advertisement -





Sometimes, you need to get maximum key value of your array but you try to get with loop and any function etc, but in bellow example you can see we can get biggest key value from our php array by using max() and array_keys(). So, let’s try to use in your code this way:

Example:

$myArray = ['2'=>'Hey','4'=>'Hello','1'=>'Hi','3'=>'GH'];

$new_key = max(array_keys($myArray));

$new_val = $myArray[$new_key];

print_r($new_val);

- Advertisement -

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles