Php array find next / prev keys

//Google Translate Version //Original Version: Turkish

For example, suppose we have a set of $array, and we assume we know a value $value in this array.

To find the previous and next keys according to the searched value

 

if(is_array($array)){
   $current_index = array_search($value, $array);
   $prevKey = $current_index - 1;
}

if(is_array($array)){
   $current_index = array_search($value, $array);
   $nextKey = $current_index + 1;
}

 


Posted in "PHP" Views 5164            Published 16/02/2018

All Comments (0)
No Comments