How to assign to a json value all values from particular array keys.
$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);
Now when i output $json i get:
{"model":"new","company":"Lexus"}
Why it doesn't assign all title values like this?
{"model":"new","company":"BMW, Jeep, Lexus"}