File:
[
{
"Zustand":"geschlossen",
"Losnummer":1,
"Gewinnklasse":"A",
"Preis":10
},
{
"Zustand":"geschlossen",
"Losnummer":2,
"Gewinnklasse":"B",
"Preis":20
},
{
"Zustand":"geschlossen",
"Losnummer":3,
"Gewinnklasse":"B",
"Preis":30
}
]
I want an array of it so i do:
<?php
$str = file_get_contents("lose.json");
$json = json_decode($str, true);
?>
And then i want to enter a value and this value should identify the entry from the Array and delete the whole entry:
<?php
if (($key = array_search(10, $json)) !== false) {
unset($json[$key]);
echo"test";
}
?>
I entered the value: 10 so the first entry of the array should be deleted.
I think array_search cant read my $json but i dont know why. Can smb fix this ?
array_searchcompares against the elements on the top level, which are themselves arrays here. Trying to compare an array with10of course does not result in true.