• Based on query data using Eloquent in Laravel models or retrieving data from RESTful APIs, we have the following JSON string:
$jsonString = [{"instruction_id":131},{"instruction_id":132},{"instruction_id":133},{"instruction_id":134}];
• In PHP function, we have solution to convert JSON data into PHP arrays or objects.
json_decode($jsonString, true)
For example:
$jsonString = [{"instruction_id":131},{"instruction_id":132},{"instruction_id":133},{"instruction_id":134}];
$instruction_ids = array_map(function($item) {
return $item['instruction_id'];
}, json_decode($jsonString, true));
$jsonStringWithComma = implode(',', $instruction_ids);