我有一个关于多维数组的简单问题,我想删除任何多余的元素,比如说在我的情况下,[serviceMethod] => PL
要来 2 次,我想搜索“PL”,以了解[APIPriceTax]
我想要的元素是否有更低的价格保留它并删除数组中的另一个
Array (
[0] => Array (
[carrierIDs] => 150
[serviceMethod] => CP
[APIPriceTax] => 30.63
[APIPriceWithOutTax] 28.32
[APIServiceName] => Xpresspost USA
[APIExpectedTransitDay] => 2
)
[1] => Array (
[carrierIDs] => 155
[serviceMethod] => PL
[APIPriceTax] => 84.13
[APIPriceWithOutTax] => 73.8
[APIServiceName] => PurolatorExpressU.S.
[APIExpectedTransitDay] => 1
)
[2] => Array (
[carrierIDs] => 164
[serviceMethod] => PL
[APIPriceTax] => 25.48
[APIPriceWithOutTax] => 22.35
[APIServiceName] => PurolatorGroundU.S.
[APIExpectedTransitDay] => 3
)
)
这是我的伪代码:$carrierAddedToList
实际数组在哪里
$newCarrierAry = function($carrierAddedToList)
{
$newArray = array();
foreach($carrierAddedToList as $cV => $cK)
{
if( !in_array($cK['serviceMethod'],$newArray) )
{
array_push($newArray, $cK['serviceMethod']);
}
}
return $newArray;
} ;
print_r($newCarrierAry($carrierAddedToList));