0
我會再做連接的foreach循環並連接同一陣列
Foreach (item as $orderitem) {
//for each item I have to get the array below
$prodord[] .= array(
'variant_id' => $variant_id,
'quantity' => 2
);
$orderData = array('order' => array(
'line_items' => array(
//the following variable is when I need to put the array if is one item
//or two arrays if are two item
$prodord
/*array(
'variant_id' => $variant_id,
'quantity' => 1
)*/
)
));
我試圖以連接陣列內部變量數組有一個變量值,這樣
//First item
array(
'variant_id' => 123456,
'quantity' => 1
),
//2d item
array(
'variant_id' => 654321,
'quantity' => 1
)
但我輸出看起來像
array(2) {
[0]=>
string(5) "Array"
[1]=>
string(5) "Array"
}
有一個項目,它的作品完美。
只要忘記點''',就是字符串連接:'$ prodord [] = array(.........'']'語法創建一個新的數組元素。 – AbraCadaver