I have a PHP variable like:
$genre = 'crime / thriller / mystery / adventure';
I use the following piece of code to convert it to an array of genres:
$return['movie_genre'] = array_map('trim', explode('/', $genre));
I also have another reference array, like:
$references = array(
'crime' => 9896,
'biography' => 9898,
'western' => 9899,
'drama' => 9901,
'action' => 9902,
'news' => 9903,
'sci-fi' => 9904,
'thriller' => 9906,
'history' => 9907,
'animation' => 9909,
'comedy' => 9910,
'musical' => 9911,
'music' => 9912,
'mystery' => 9913,
'documentary' => 9914,
'family' => 9915,
'adventure' => 9916,
'war' => 9917,
'reality-tv' => 9919,
'romance' => 9920,
'sport' => 9921,
'game-show' => 9922,
'talk-show' => 9923,
'horror' => 9924,
'fantasy' => 9925,
'film-noir' => 9926,
);
, where I'd like to lookup the textual values of the first array, and replace them with their numerical references of the reference array, ending up to something like this (for the above example):
[movie_genre] => Array
(
[0] => 9896
[1] => 9906
[2] => 9913
[3] => 9916
)
Let me be clear, I'm not looking for a foreach solution. That one, I can write myself. I'm looking for an elegant one-liner, like another array_map, or array_walk; ideally if I could combine it with the one-liner I already use to create the array itself from the initial string variable. But I can't thing of anything elegant... Any help would be much appreciated. TIA.