[Urgent] PHP - Filtering a nested array based on another array.

dannyl

Member
May 7, 2020
85
47
18
I have a nested multidimensional array $field_list that I need to filter based on what truthy values are in a different array $args. Any suggestions?

PHP:
$args = [
    'author' => $author;
    'date' => $date;
    'cost' => $cost // is falsey
];

$field_list = [
    'post' => [
        'header' => [ 'date','cost', 'location' ],
        'body' => ['author', 'snippet'],
        'footer' => ['category'],
    ],
    'page' => [
        //etc.
    ],
    //etc.
];

After filtering, $field_list should be:
PHP:
$field_list = [
    'post' => [
        'header' => [ 'date' ],
        'body' => ['author' ], 
        'footer' =>[],
    ],
    'page' => [
        //etc.
    ],
    //etc.
];

Any suggestions?
 

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu