Find the mid element of the array in php


How to find the mid element of the array in php 

$arr = array('5','7','4','5','7','6','5','7','1','6','7','9','5','7','4');
// Find the array size 
$total_size_of_array = count($arr);
$mid = $total_size_of_array / 2 ;
if(gettype($mid) == 'array'){
    $midd = round($mid);
}else{
    $mid = $mid ;
}
print_r ($arr[$mid]);

Result is : 7

Comments

Post a Comment

Popular posts from this blog

your device is corrupted and cannot be trusted asus zenfone max pro m1 | your device is corrupted it cannot be trusted and may not work properly asus

how to earn money from amazon affiliate program