I have a multidimensional array in php like this:
Array
(
[0] => Array
(
[Year_id] => 29
[Make_id] => 7
[Model_id] => 34
[Engine_id] => 19
)
[1] => Array
(
[Year_id] => 30
[Make_id] => 7
[Model_id] => 34
[Engine_id] => 19
)
[2] => Array
(
[Year_id] => 21
[Make_id] => 7
[Model_id] => 34
[Engine_id] => 19
)
[3] => Array
(
[Year_id] => 1
[Make_id] => 7
[Model_id] => 34
[Engine_id] => 19
)
[4] => Array
(
[Year_id] => 2
[Make_id] => 7
[Model_id] => 34
[Engine_id] => 2
)
[5] => Array
(
[Year_id] => 3
[Make_id] => 7
[Model_id] => 34
[Engine_id] => 2
)
[6] => Array
(
[Year_id] => 4
[Make_id] => 7
[Model_id] => 34
[Engine_id] => 2
)
)
My code is as follows:
<?php
$cars = array
(
array("Year_id"=>29, "Make_id"=>7, "Model_id"=>34, "Engine_id"=>19),
array("Year_id"=>30, "Make_id"=>7, "Model_id"=>34, "Engine_id"=>19),
array("Year_id"=>21, "Make_id"=>7, "Model_id"=>34, "Engine_id"=>19),
array("Year_id"=>1, "Make_id"=>7, "Model_id"=>34, "Engine_id"=>19),
array("Year_id"=>2, "Make_id"=>7, "Model_id"=>34, "Engine_id"=>2),
array("Year_id"=>3, "Make_id"=>7, "Model_id"=>34, "Engine_id"=>2),
array("Year_id"=>4, "Make_id"=>7, "Model_id"=>34, "Engine_id"=>2)
);
echo '<pre>';
print_r($cars);
?>
In above result, I have four ids named Year_id
, Make_id
, Model_id
and Engine_id
. Year_id
may change any time but when any of remaining IDs change in value, I want to store those arrays in a separate array and again check for remaining arrays and when any of ID values change except Year_id
, store those arrays in a separate array.
Right now it should store first four arrays in a separate array because Engine_id
value changes. How to solve it? I am ready for bounty after 2 days.