3 回答

TA貢獻1851條經(jīng)驗 獲得超3個贊
您可以使用foreach迭代中的每個項目$array['recommendationProductDetails']。$newArray將保留提取的值:
$newArray = array();
foreach ($array['recommendationProductDetails'] as $arrayItem) {
array_push($newArray, $arrayItem['productId']);
}
print_r($newArray);
將輸出
Array
(
[0] => 7053
[1] => 4610
[2] => 4591
[3] => 1756
)

TA貢獻1793條經(jīng)驗 獲得超6個贊
PHP 中是否有從數(shù)組中提取“列”的函數(shù)?
是的,有array_column(array $input, mixed $column_key [, mixed $index_key = NULL])
?
所以在你的代碼中:array_column($array['recommendationProductDetails'], 'productId');

TA貢獻1847條經(jīng)驗 獲得超11個贊
array_column(array $input, mixed $column_key [, mixed $index_key = NULL]) 文檔
array_column($array['recommendationProductDetails'], 'productId');
- 3 回答
- 0 關(guān)注
- 190 瀏覽
添加回答
舉報