I have an array like this:
Array (
0 => Array (
'id' => 1,
'name' => 'Hack n\' Slash',
'slug' => 'hack-n-slash',
'popular' => 0
),
1 => Array (
'id' => 2,
'name' => 'FPP',
'slug' => 'fpp',
'popular' => 1
),
2 => Array (
'id' => 3,
'name' => 'RPG',
'slug' => 'rpg',
'popular' => 1
)
)
What I want, is to split it into two arrays by key popular, so I’ll have a list like:
Popular:
- one
- two
Non-popular:
- one
- two
I tried using if/else like this:
foreach($genres as $genre) :
if($genre['popular'] == '1' :
echo $genre['name'];
endif;
endforeach;
But then, when I added another statement (if($genre['popular'] == '0')), I couldn’t use it, since it was quite messy.
How can I achieve this?
A more generic solution, making use of PHP closures