我正在尝试将两组数组与同一个键进行比较
product_sku
API上的数组(JSON响应)
$array1 = array (
"products" => array(
"category" => array(
array(
"product_sku" => "1",
"product_type" => "Type",
"customer_contact_name" => "Contact Name",
"customer_telephone" => "0000 000 000",
"customer_email" => "email@email.com",
"customer_postcode" => "PostCode",
"additional_info" => array(
"some information" => "some information"
),
"full_price" => "50.00",
"product_name" => "Product Name",
"product_id" => "1",
"customer_rating" => "0"
),
array(
"product_sku" => "2",
"product_type" => "Type",
"customer_contact_name" => "Contact Name",
"customer_telephone" => "0000 000 000",
"customer_email" => "email@email.com",
"customer_postcode" => "PostCode",
"additional_info" => array(
"some information" => "some information"
),
"full_price" => "100.00",
"product_name" => "Product Name",
"product_id" => "2",
"customer_rating" => "0"
)
)
)
);
本地数据库上的数组(mysqli查询)
$array2 = array (
array(
"product_sku" => "1",
"product_type" => "Type",
"contact_name" => "Contact Name",
"phone" => "0000 000 000",
"full_price" => "0.00",
"product_name" => "Product Name",
"product_id" => "1",
"rating" => "0"
),
array(
"product_sku" => "3",
"product_type" => "Type",
"contact_name" => "Contact Name",
"phone" => "0000 000 000",
"full_price" => "80.00",
"product_name" => "Product Name",
"product_id" => "3",
"rating" => "0"
)
);
目标是
-
检查
$array2
反对
$array1
只有在
产品\库存单位
匹配(存在于
$array1美元
)获取
full_price
从
$array1美元
并更换
全价
价值
$array2美元
-
如果
product_id
在里面
$array1美元
不存在于
$array2美元
忽略这些产品。
-
分类产品价格(从低到高)使用
sort
功能
我所尝试的是,部分工作,但无法使用分类产品价格(从低到高)
分类
功能,显示0.00
全价
一些产品的价值
$apiarray = $array1["products"]["category"];
foreach ($array2 as $arr2) {
foreach ($apiarray as $arr1) {
if ($arr1['product_sku']==$arr2['product_sku']) {
echo $arr2['product_sku']; // Product from $array2
echo number_format($arr1['full_price'],2); // Price from $array1
} else {
echo $arr2['product_sku']; // Product from $array2
echo number_format($arr2['full_price'],2); // Price from $array2
}
}
)
我需要帮助来解决问题,或者给我指明正确的方向,我如何才能实现目标