For example i did this code
<?php
$arr= [12, 24,17,49];
foreach ($arr as $value) {
if ($value % 2 == 0)
$max = $value + 1;
else
$max = $value - 1;
var_dump($max);
echo $max;
}
?>
it works perfectly but why when it comes to multidimensional arrays like these:
<?php
$arr= array (
array (12, 24, 17, 49 ),
array (10, 4, 99, 74)
);
foreach ($arr as $value) {
if ($value % 2 == 0)
$max = $value + 1;
else
$max = $value - 1;
var_dump($value);
echo $value;
}
?>
Code just wont work,tried alot of variations, dont know what clue i am missing.
$valueis an array in the second example because it is multi-dimensional. Theforeachgoes 1 level in so on the first one your get12then24, etc. On the second on you getarray (12, 24, 17, 49 )thenarray (10, 4, 99, 74).