Friends I have an array that comes from a database with the following format:
["2018-07-25","2018-07-26","2018-07-26"]
With a json decode I convert it into an array, in order to be able to treat it since the code is to find a date and remove it from the array and then return it to the database.
To do that I use the following code:
$ls['fecha']
is the text with the array that comes from the database.
$_POST['glo']
is the date to search.
$arra = json_decode($ls['fecha']);
if (in_array($_POST['glo'], $arra, true)) {
$este = array_keys($arra, $_POST['glo']);
$clave = array_search($_POST['glo'], $arra);
unset($arra[intval($clave)]);
$sql = "UPDATE tabla SET fecha = '".json_encode($arra, JSON_UNESCAPED_UNICODE)."' WHERE r = '".$_POST['r']."'";
$con = mysqli_query($conx, $sql);
}
In fact it looks for and deletes the date but when saving the array again in the db it changes the format of the array, like this:
{"0":"2018-07-25","2":"2018-07-26"}
And I need the array to be like this:
["2018-07-25","2018-07-26"]
Any Solution ?? or something am I doing wrong ?? A thousand thanks