<?php
$json = '[
{
"surname": "",
"name": "Andrea Fiore",
"city": "Crocino",
"address": "via Emo Mannucci, 2",
"telephone": "123456789",
"email": "x@gmail.com",
"startData": "2019-07-04",
"finishData": "2019-07-25",
"cardId": "2",
"state": "true"
}
]';
$data = json_decode($json, true);
$filter = array_filter($data, function($row) {
return $row['email'] == 'x@gmail.com';
});
if(count(($indexs = array_keys($filter))) == 1) {
$data[$indexs[0]] = array(
'foo' => 'bar',
);
}
var_dump($data);
- Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.13
- array(1) {
[0]=>
array(1) {
["foo"]=>
string(3) "bar"
}
}
preferences:
160.27 ms | 407 KiB | 5 Q