I have the following two arrays.
This is a flat array (string: $second_names):
Array ( [0] => Cars [3] => Bikes [8] => Trucks ) //$second_names
I have this multidimensional array - (string: $premiumCatArraySets):
Array
(
[0] => Array
(
[primary-category] => Automobiles
[secondary-category] => Cars
[tertiary-category] => Fiat Punto
)
[1] => Array
(
[primary-category] => Automobiles
[secondary-category] => Cars
[tertiary-category] => BMW
)
[2] => Array
(
[primary-category] => Automobiles
[secondary-category] => Bikes
[tertiary-category] => Honda
)
[4] => Array
(
[primary-category] => Automobiles
[secondary-category] => Trucks
[tertiary-category] => Iveco
)
[6] => Array
(
[primary-category] => Automobiles
[secondary-category] => Cars
[tertiary-category] => Mercedes
)
[9] => Array
(
[primary-category] => Automobiles
[secondary-category] => Cars
[tertiary-category] => Toyota
)
I am trying to use in_array to see whether the values in the flat array exist and output the brand of the car.
This is what I tried
foreach ($second_names as $second_name) {//Vechile type e.g. car, truck, bike
if(in_array($second_name, $premiumCatArraySets)){
echo '<h2>'.$second_name.'</h2>';
foreach ($third_names as $third_name) {// e.g. Fiat, BMW, Toyota
echo $third_name.'<br/>';
}
}
}
The line for if(in_array($second_name, $premiumCatArraySets)){ doesn't seem to be displaying anything.