I have a multidimensional array like below.
$test = Array
(
[0] => Array
(
[0] => 38
[1] => 3
[2] => 7
[3] => 2
[4] => 232
[5] => 1
[6] => 58
)
[1] => Array
(
[0] => 8
[1] => 13
[2] => 7
[3] => 2
[4] => 232
[5] => 11
[6] => 58
)
)
and i want to push a array element like
$new = Array
(
[0] => 38
[1] => 3
[2] => 7
[3] => 2
[4] => 232
[5] => 1
[6] => 58
)
so it should be compare with all the inner array key elements of multidimensional array and if it matches with any of the inner array like $test[n][0] = $new[0],$test[n][1] = $new[1],$test[n][2] = $new[2],$test[n][3] = $new[3],$test[n][4] = $new[4] then the result should be like this.(because in our case $test[0] is matching)
Array
(
[0] => Array
(
[0] => 38
[1] => 3
[2] => 7
[3] => 2
[4] => 232
[5] => 2 ====> $test[0][5] + $new[5] //updating 1+1 = 2
[6] => 58
)
[1] => Array
(
[0] => 8
[1] => 13
[2] => 7
[3] => 2
[4] => 232
[5] => 11
[6] => 58
)
)
and test array is having 'n' array in it.
Thank You any help will be appriciated.
foreach($test as $key=>$val){
if($val[0] == $new[0] && $val[1] == $new[1] && $val[2] == $new[2] && $val[3] == $new[3] && $val[4] == $new[4]){
$val[5] = $val[5] + $new[5];
}else{
array_push($test, $new);
}
}
print_r($test);