简体   繁体   中英

PHP 3rd level multidimensional array filter

I have a 3 level multidimensional array

Array (
//first element
[7d69562076b7c92d82abd4333ee13ef9] =>
Array ( [unique_key] => 23f740a5eced0146558773804eab9f7a
[thwepof_options] => Array (
[order_date] => Array (
[name] => order_date
[value] => 05-02-2018, monday
[label] => Order Date [options] => ) )
[key] => 7d69562076b7c92d82abd4333ee13ef9
[product_id] => 528
[variation_id] => 616
[variation] => Array ( )
[quantity] => 1  ) )
//second element
[d9c2651b57c8b352502d908cbc69fb81] =>
Array ( [unique_key] => e6ed57f68d1f4613a502db45a0abaa59
[thwepof_options] => Array (
[order_date] => Array (
[name] => order_date
[value] => 06-02-2018, tuesday
[label] => Order Date [options] => ) )
[key] => d9c2651b57c8b352502d908cbc69fb81
[product_id] => 528
[variation_id] => 767 
[variation] => Array ( )
[quantity] => 1 ) ) )

I have an $order_date_value variable which value is

06-02-2018, tuesday

or later

05-02-2018, monday

etc.

So it's dinamic. I would like to remove those elements from the array where [thwepof_options][value]=> isn't equal with my $order_date_value .

Like if my value is tuesday, then remove the second element and keep the first element.

I'd suggest using array_filter . Within your callback function you could then determine whether or not the value should stay in the array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM