【发布时间】:2018-07-07 15:38:22
【问题描述】:
我找到了this manual page,但我仍然不确定要使用什么。我有这个数组:
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 进行 foreach,对它们进行排序并使其独一无二(因为我需要一次):
<?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] 不相等的每个值(或仅显示那些相等的值)以创建另一个foreach 循环。
【问题讨论】:
标签: php arrays wordpress function filter