I'm studying how to manipulate array in PHP. Now, I have a issue about multidimensional array. I want to reverse 2d array without any sort method.This issue doesn't allow us to use array_reverse.
$numArray = array(1,2,3,array(4,5,6),7);
function numReverse($num) {
$reverseArray=array();
$subValueArr=array();
for($count=count($num), $i=$count-1; $i >= 0; $i--){
$reverseArray[]=$num[$i];
}
foreach($num as $value){
If(is_array($value)){
for($subCount=count($value),$j=$subCount-1; $j--){
$subValueArr[]=$value[$j];
}
}
}
$reverseArray[1][]=$subValueArr;
return $reverseArray;
}
$result=numReverse($numArray);
print_r($result);
I expect this output
array{int(7),array{int(6),int(5),int(4)},int(3),int(2),int(1)}
count(array_size)-(original array position).