This commit is contained in:
paoloar77
2024-05-19 16:31:05 +02:00
parent ad49e1382b
commit 5488460e3d

View File

@@ -28,17 +28,18 @@ function getValueByKey($array, $key)
// Funzione per aggiornare il valore di un certo key in un array di oggetti
function updateValueByKey(&$array, $key, $newValue) {
foreach ($array as &$item) {
if ($item->key === $key) {
if (is_object($item) && property_exists($item, 'key') && $item->key === $key) {
$item->value = $newValue;
break; // Se trova il key, termina il loop
return; // Se trova il key, termina il loop
}
}
// push the new value in the array
$array[] = [
'key' => $key,
'value' => $newValue
];
// Se il key non esiste nell'array, aggiungi il nuovo key-value pair
$newItem = new stdClass();
$newItem->key = $key;
$newItem->value = $newValue;
$array[] = $newItem; // Aggiungi il nuovo elemento all'array
}
function updateValueByKeyArr(&$array, $key, $newValue) {