$array = array();
foreach( $order->get_items() as $item_id => $item ) {
$rray = array(
'name'=>$item['name'],
'qty'=>$item['qty']
);
$array[] = $rray;
}
}
我有如上所述的数组 如何创建一个如下所示的字符串: ' name qty,name qty,name qty,name qty,name qty,name qty,name qty,'
'阿富汗库什1,石榴蓝锉1,蓝莓香草1,香蕉草莓1,焦糖卡布奇诺1,'
答案 0 :(得分:1)
尝试:
$array_text = implode(', ', array_map(function ($e) { return $e['name'] . ' ' . $e['qty']; }, $array));
答案 1 :(得分:1)
np.where(my != 0)
答案 2 :(得分:1)
您可以使用array_map()
和implode()
。
$array = [
[
'name' => 'Blackberry Kush',
'qty' => '1'
],
[
'name' => 'Granddaddy Purple',
'qty' => '1'
],
[
'name' => '20% THC',
'qty' => '1'
],
[
'name' => 'Pomegranate Blue-Rasp',
'qty' => '1'
],
[
'name' => 'Blueberry Vanilla',
'qty' => '2'
],
[
'name' => 'Banana Strawberry',
'qty' => '3'
]
];
$formatted = array_map( function($obj) {
return "{$obj['name']} {$obj['qty']}";
}, $array );
echo implode( ', ', $formatted );
<强> Example 强>
答案 3 :(得分:0)
$array = array();
foreach( $order->get_items() as $item_id => $item ) {
$rray = array(
'name'=>$item['name'],
'qty'=>$item['qty']
);
$array[] = $rray;
}
foreach($array as $key => $value) {
$result .= $value['name']." ". $value['qty'];
$result .= ", ";
}
var_dump($result);
像冠军一样工作!