Как достать из массива все значения price
То есть нужно получить 2,3,300,10000,2,455
Array
(
[0] => stdClass Object
(
[status] =>
[sentences] => [{"index":"0","price":"2","amount":"5"},{"index":"1","price":"3","amount":"100"},{"index":"2","price":"300","amount":"5"},{"index":"3","price":"100000","amount":"1000"}]
[id] => 825
[userid] => 1
[auction_id] => 2949
[bid] => 100305.0000
[date] => 2021-02-26 13:29:52
[proxy] => 0
)
[1] => stdClass Object
(
[status] =>
[sentences] => [{"index":"0","price":"2","amount":"5"},{"index":"1","price":"455","amount":"100"}]
[id] => 826
[userid] => 187
[auction_id] => 2949
[bid] => 457.0000
[date] => 2021-02-26 12:56:31
[proxy] => 0
)
)
foreach($query_result->sentences as $index => $arSentence) {
echo $arSentence['price'];
}
Ответы (2 шт):
Автор решения: Дмитрий Березуцкий
→ Ссылка
$sentences = array_column($query_result, 'sentences');
$prices = [];
foreach($sentences as $item) {
$prices = array_merge($prices, array_column($item, 'price'));
}
Автор решения: Сергей Дрогалов
→ Ссылка
$sentences = array_column($query_result, 'sentences');
$prices = [];
foreach($sentences as $item => $arItem) {
$arItem = json_decode($arItem, true);
$prices = array_merge($prices, array_column($arItem, 'price'));
}