avatar
extract values from an array of associative arrays PHP

• 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);
24
extract values from an array based on IDs in PHP extract the UNIX timestamp string to the array of ISO date string extract column from array
You need to login to do this manipulation!