- json_decode: documentation ( source)
- array_column: documentation ( source)
- json_encode: documentation ( source)
<?php
$content = '[
{
"id": 1,
"content": "Reason 1"
},
{
"id": 2,
"content": "Reason 2"
},
{
"id": 3,
"content": "Reason 3"
},
{
"id": 4,
"content": "Reason 4"
}
]';
$from = json_decode($content, true);
$to = json_encode(array_column($from, 'content', 'id'), JSON_PRETTY_PRINT);
echo $to;