如果$array
与[productType]
匹配,我如何解析下面的多维数组([totalPrice]
)并提取[productCategory]
,[packageCode]
和$pkgcodes[1]...[z]
的值值$pkgcodes
$pkgcodes
是一个代码数组
Array ( [0] => TRA1I2 [1] => TREZEC [n] ...)
$array
数组$array
是SOAP客户端的响应
Array (
[0] => Array (
[packageCode] => TRA1I2
[totalPrice] => 17
[productType] => product Only
[products] => Array (
[0] => Array (
[productCategory] => Simple
[paxes] => Array (
[0] => Array (
[paxType] => Adult
[age] => 30 )
[1] => Array (
[paxType] => Adult
[age] => 30 ) )
[totalproductRate] => 17
[ratesPerNight] => Array (
[0] => Array (
[date] => 2015-01-28
[amount] => 17 ) ) ) ) )
[1] => Array (
[packageCode] => TREZEC
[totalPrice] => 17
[productType] => product Only
[products] => Array (
[0] => Array (
[productCategory] => Complicated
[paxes] => Array (
[0] => Array (
[paxType] => Adult
[age] => 30 )
[1] => Array (
[paxType] => Adult
[age] => 30 ) )
[totalproductRate] => 17
[ratesPerNight] => Array (
[0] => Array (
[date] => 2015-01-28
[amount] => 17 ) ) ) ) ) ).
{{1}}
你更感谢你的帮助
答案 0 :(得分:0)
尝试 -
$newArr = array();
foreach($array as $value) {
if (in_array($value['packageCode'], $pkgcodes)) {
$temp['productType'] = $value['productType'];
$temp['totalPrice'] = $value['totalPrice'];
$temp['packageCode'] = $value['packageCode'];
$temp['productCategory'] = $value['products']['productCategory'];
$newArr[] = $temp;
}
}
var_dump($newArr);