【发布时间】:2019-09-12 11:27:59
【问题描述】:
如何将来自特定数组键的所有值分配给 json 值。
$cars = Array ( [0] => Array ( [category] => Most Selling [title] => BMW [price] => 20000 ) [1] => Array ( [category] => Most Selling [title] => Jeep [price] => 15000) [2] => Array ( [category] => Most Selling [title] => Lexus [price] => 18000 ) )
foreach ( $cars as $car) {
$data = [
'model' => 'new',
'company' => $car['title'],
];
}
$json = json_encode($data);
现在当我输出 $json 我得到:
{"model":"new","company":"Lexus"}
为什么它没有像这样分配所有标题值?
{"model":"new","company":"BMW, Jeep, Lexus"}
【问题讨论】:
标签: php arrays json wordpress api