How to get maximum key value of array in PHP?By Hardik Savani | March 2, 2016 | | 1121 Viewer | Category : PHP
Share this post:
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:
$myArray = ['2'=>'Hey','4'=>'Hello','1'=>'Hi','3'=>'GH'];
$new_key = max(array_keys($myArray));
$new_val = $myArray[$new_key];
- How to check column exists or not in table Laravel 5
- Solved Issue - "/usr/bin/env: ‘node’: No such file or directory"
- How to generate slug using str_slug() helper in Laravel 5?
- Dynamic Autocomplete search using Bootstrap Typeahead JS Example
- How to get current url with query string in codeigniter?
- Paypal payment gateway integration in php source code example
- Bootstrap Color Picker Example using mjolnic colorpicker plugin
- How to get filename without extension in PHP?