i have predefined array of categories like this in key => value pair
$all_categories = array (
1 => 'friends',
2 => 'family',
3 => 'personal',
4 => 'public'
);
and i have new small array like this which are only values.
$searched_categories = array('family','public');
Now how can i get the keys from $all_categories array having values as $searched_categories ?
i want output like this
$output_array = array(2,4);
i can get single key using array_search but is there a prebuilt function for this ? or i have to create a loop to array_search all the values i have ?
is this proper way of achieving this ?
$output_array = array ();
foreach ($searched_categories as $value){
$key = array_search($value, $all_categories );
$output_array = $key;
}