<input type="hidden" name="gallery[0]" value="gallery-image-1500382700392.jpeg">
<input type="hidden" name="gallery[1]" value="gallery-image-1500382700392.jpeg">
<input type="hidden" name="gallery[2]" value="gallery-image-1500382700392.jpeg">
This is the form elements.In my admin panel i have the facility to delete images in the art gallery.If I am deleting name="gallery[2]" element, data saved to database is
["gallery-image-1500382700392.jpeg", "gallery-image-1500382700392.jpeg"]
and the format is json array
But if Iam deleting name="gallery[1]" element, data saved to database is of json object format.
{"0": "gallery-image-1500295044382.jpeg","2": "gallery-image-1500295044382.jpeg"}
I think this is because array indexing is not there [0,1] so treated as just key-value pair
I there any way to re-order this indexing?
You can use array_values to reset the keys of an array and Return all the values of an array.
Here is example,
<?php
$a = array(
3 => 11,
1 => 22,
2 => 33,
);
$a[0] = 44;
print_r( array_values( $a ));
==>
Array(
[0] => 11
[1] => 22
[2] => 33
[3] => 44
)
?>