I got this code:
function deleteClient(){
global $database;
$input = 2;
if (array_key_exists($input, $database)){
$database.array_splice($database, $input, 1);
echo "Client with id $input deleted succesfully";
} else {
echo "Client with this id doesn't exist";
}
}
Variable $database is my two-dimensional array. Although array_splice deletes array with given index, it shows an error “Warning: Array to string conversion”. Everything else works properly.
I tried doing it with unset:
function deleteClient(){
global $database;
$input = 2;
if (array_key_exists($input, $database)){
unset($database[$input]);
echo "Client with id $input deleted succesfully";
} else {
echo "Client with this id doesn't exist";
}
}
It doesn’t return an error, but makes gaps in array which breaks another function.