- var_dump: documentation ( source)
- json_decode: documentation ( source)
<?php
$arrays = json_decode('[
{
"id": 0,
"title": "a title"
},
{
"id": 1,
"title": "another title"
},
{
"id": 2,
"title": "one more title"
}
]', true);
$array = [
'id' => 1,
'title' => 'a different title',
];
foreach ($arrays as &$value) {
if ($value['id'] === $array['id']) {
$value = $array;
}
}
unset($value);
var_dump($arrays);