Answer the question
In order to leave comments, you need to log in
How to get key-value string from PHP array?
There is an array
Array
(
[0] => 31
[1] => 5
[2] => 6
[3] => 4
)
json_encode($a)
{"1":31, "2":5, "3":6, "4":4}
Answer the question
In order to leave comments, you need to log in
how can i get this resultIncrement all keys by one. If an associative array has a key of 0 , this array is converted to json exactly as an array, not as an object.
$a = [31, 5, 6, 4];
for ($index = count($a); $index > 0; $index--) {
$a[$index] = $a[$index - 1];
unset($a[$index - 1]);
}
ksort($a);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question