I wonder how to do this. I have two arrays, I need to assign them into a variable. The example below shows the output. When I print out the output using print_r()
, the value that I want to match is "id_car"..
1) variable used for this array is $data.
Array ( [0] => 26 )
2) variable used for this array is $dataKereta.
Array ( [0] => Array ( [0] => 25 [id_car] => 25 [1] => 23 [id_user] => 23 )
[1] => Array ( [0] => 26 [id_car] => 26 [1] => 23 [id_user] => 24)
[2] => Array ( [0] => 27 [id_car] => 27 [1] => 23 [id_user] => 25 ) )
what i want is, find the same value in 1st array with 2nd array,if same assign them into variable..
I tried do like this
foreach ($dataKereta as $dk => $dk1) {
if($data[$dk] != $dk1['id_car']) {
$not_same[] = $dk1;
}
else {
$same[] = $dk1;
}
}
The code I made above has find the match value, if not match assign into the $not_same variable and otherwise.. this code is OK when have the value for 1st variable like this :
Array ( [0] => 25 [1] => 26 )
but if i remove the "[0] => 25" value,it start not detect the 26.. i'm sorry for bad english.