I have this array:
$priceTableData = array(
array('productId'=>1,'price'=>50,'discount'=>12),
array('productId'=>2,'price'=>22,'discount'=>2),
array('productId'=>3,'price'=>7,'discount'=>0),
array('productId'=>4,'price'=>9,'discount'=>0),
array('productId'=>5,'price'=>35,'discount'=>7),
);
and I want to get this array out of it:
array(5) {
[1]=> int(12)
[2]=> int(2)
[3]=> int(0)
[4]=> int(0)
[5]=> int(7)
}
and I used this custom method to do so,
function getDiscounts(array $priceData){
$result = array();
foreach ($priceData as $array){
$result[$array['productId']] = $array['discount'];
}
return $result;
}
then I used it as this:
var_dump(getDiscounts($priceTableData));
my question is: is there a native way of doing so, rather than having a custom function for it?
Thanks.