Dies ist der Code:PHP - ein Array erstellen Der Versuch scheint nicht
function create_order_with_custom_products()
{
$orderGenerator = new OrderGenerator();
$orderGenerator->setCustomer(6907);
$orderGenerator->createOrder(array(
// Add configurable product
array(
'product' => 30151,
'qty' => 1
), array(
'product' => 30150,
'qty' => 2
),
));
}
Ich habe Array mit einer solchen Struktur zu schaffen:
array(
'product' => 30151,
'qty' => 1
), array(
'product' => 30150,
'qty' => 2
),
Ich versuche, ein Array mit erstellen gleiche Struktur wie folgt aus:
foreach($ItemsInCart['productid'] as $key=>$value){
$ProductId = $value;
$ProductQty = $ItemsInCart["productqty"][$key];
$product_id = $ProductId; // Replace id with your product id
$qty = $ProductQty; // Replace qty with your qty
$ItemsId[] = ['product' => $ProductId, 'qty' => $ProductQty];
}
Das gibt mir Ergebnis:
Array ([0] => Array ([Produkt] => 30143 [Menge] => 1) [1] => Array ( [Produkt] => 30144 [Menge] => 2) [2] => Array ([Produkt] => 30145 [Menge] => 3) [3] => Array ([Produkt] => 30146 [Menge] => 4) [4] => Array ([Produkt] = > 30147 [Menge] => 5))
Alles, was ich wissen will, ist, warum dies:
function create_order_with_custom_products()
{
$orderGenerator = new OrderGenerator();
$orderGenerator->setCustomer(6907);
$orderGenerator->createOrder(array(
// Add configurable product
array(
'product' => 30151,
'qty' => 1
), array(
'product' => 30150,
'qty' => 2
),
));
}
nicht das gleiche wie das ist:
function create_order_with_custom_products()
{
$orderGenerator = new OrderGenerator();
$orderGenerator->setCustomer(6907);
$orderGenerator->createOrder(array($ItemsId));
}
Warum der zweite Ansatz nicht funktioniert, wo ist mein Fehler?
Ersetzen Sie $ AUTHEID [] ["product"] = $ ProductId; $ ItemsId [] ["Menge"] = $ ProductQty; 'mit' $ ItemsId [] = ['Produkt' => $ ProductId, 'Menge' => $ ProductQty]; ' –
Ich habe meine Frage über Sie gestellt Bitte schau es dir an. –