[英]PHP multidimensional array filter
我找到了此手册页,但是我仍然不确定该使用什么。 我有这个数组:
Array (
[unique_key] => 7439db65fe2856a636e3c6d9841b51ed
[thwepof_options] => Array (
[order_date] => Array (
[name] => order_date
[value] => 29-01-2018, monday
[label] => Order date [options] => ) )
因此,首先我只遍历每个[thwepof_options] => value
,对它们进行排序并使其唯一(因为我只需要一次):
<?php foreach (WC()->cart->get_cart() as $order_dates => $order_date): ?>
<?php $options = $order_date['thwepof_options']; ?>
<?php foreach($options as $option => $dates): ?>
<?php array_push($myarray, $dates['value']) ?>
<?php endforeach; ?>
<?php endforeach; ?>
<?php sort($myarray); ?>
<?php $unique = array_unique($myarray); ?>
//later in that code
<?php foreach($unique as $dates => $date_value): ?>
<tr>
<h1><?php echo $date_value ?></h1></td>
</tr>
<?php endforeach; ?>
使用WC()->cart->get_cart()
方法,我可以获得整个数组。 我需要某种过滤器,该过滤器将从$date_value
[thwepof_options] => [value]
不等于[thwepof_options] => [value]
(或仅显示相等的$date_value
)的数组中删除每个值,以进行另一个foreach
循环。
尝试这个:
array_filter(
$unique, // Array to filter
function($elem){ // Closure performing filtration
// When this returns FALSE, items will be removed
return $elem['order_date']['value'] == $date_value;
}
);
目前尚不清楚在哪里获取所有值,因为没有提供所有代码,但是我希望这能成功演示一种简单的方法来过滤数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.