This question is an exact duplicate of:
Im trying to filer out only parts of this array - by [channel] (like this):
Array
(
[0] => Array
(
[268a9d2d25fc2b9765c7cd7b8a768d3e] => Array
(
[dj_name] => Emilian
[channel] => techno
)
[5d1838c3aa6344e3109ab4f0122492f7] => Array
(
[dj_name] => Emilian
[channel] => trance
)
)
[1] => Array
(
[e13268de7c56db42f8aeab2ab4c607f2] => Array
(
[dj_name] => John Doe
[channel] => trance
)
[1aa81b7b123321f79571828600db0f08] => Array
(
[dj_name] => John Doe
[channel] => techno
)
)
So results should be (if channel is trance ) :
Array
(
[0] => Array
(
[5d1838c3aa6344e3109ab4f0122492f7] => Array
(
[dj_name] => Emilian
[channel] => trance
)
)
[1] => Array
(
[e13268de7c56db42f8aeab2ab4c607f2] => Array
(
[dj_name] => John Doe
[channel] => trance
)
)
... i have tried with foreach loops ... to unset but didnt have much succes .. also with array_filter ...
with foreach i tried like this ( but i dont know how to update the $show_data array once the loop is closed ... hmm im pretty green at php:
foreach($show_data as $idindex => $codearray){
foreach($codearray as $codestring => $paramarray) {
foreach($paramarray as $param => $val) {
if(preg_grep('/trance/', $paramarray)){
unset($paramarray[$val]);
}}}}
print_r($show_data);
And I also tried with ( but if the first one is trance then it doesnt filter out the rest.. even if they are techno ... i need it to filter out at the [5d1838c3aa6344e3109ab4f0122492f7] level ) :
$genre = 'trance';
$data = array_filter($dataraw, function($fs) use ($genre) {
return current($fs)['channel'] === $genre;
});
Thanks in advance!
</div>