我在定义我正在寻找的东西时遇到了一些麻烦,所以希望我听起来不会神秘。
我正在尝试从我的网上商店中获取一些数据,该数组存储订单中每个项目的订单信息。
我想返回此订单信息中的一些值。但是我在定位正确信息方面遇到了一些麻烦。由于我想为每个order_item返回此信息,我需要定位唯一键,并可能为每个函数编写一个。我不知道从哪里开始。
我正在返回的数组看起来像这样。例如,我将如何返回product_id's?
array(2) {
["d4650547c8d3536a6741b300f563a8fb"]=>
array(11) {
["product_id"]=>
int(259)
["variation_id"]=>
int(278)
["variation"]=>
array(1) {
["pa_afmetingen-liggend"]=>
string(4) "m011"
}
["quantity"]=>
int(1)
["data"]=>
object(WC_Product_Variation)#3243 (24) { ["variation_id"]=>
int(278)
["parent"]=>
}
["product_type"]=>
string(8) "variable"
}
array(2) {
["893hg547c8d35pga6741b300f56754ud"]=>
array(11) {
["product_id"]=>
int(279)
["variation_id"]=>
int(298)
["variation"]=>
array(1) {
["pa_afmetingen-liggend"]=>
string(4) "m011"
}
["quantity"]=>
int(1)
["data"]=>
object(WC_Product_Variation)#3243 (24) { ["variation_id"]=>
int(298)
["parent"]=>
}
["product_type"]=>
string(8) "variable"
}
答案 0 :(得分:1)
你在找这样的东西吗?
<?php
// Sample products Array
$my_products = array();
$my_products[] = array('product_id' => 230, 'product_name' => 'audi');
$my_products[] = array('product_id' => 355, 'product_name' => 'benz');
// My products
print_r($my_products);
$product_ids = array();
foreach ($my_products as $product) {
$product_ids[] = $product['product_id'];
}
// MY product ids
print_r($product_ids);
// My first product id
echo $my_products[0]['product_id'];
// My second product id
echo $my_products[1]['product_id'];
?>
// My products
Array
(
[0] => Array
(
[product_id] => 230
[product_name] => audi
)
[1] => Array
(
[product_id] => 355
[product_name] => benz
)
)
// MY product ids
Array
(
[0] => 230
[1] => 355
)
// My first product id
230
// My second product id
355