After implementing database queries, I am getting the multi-dimensional array below.
Two Dimensional Array
Array
(
[0] => Array
(
[t1] => test1
)
[1] => Array
(
[t2] => test2
)
[2] => Array
(
[t3] => test3
)
[3] => Array
(
[t4] => test4
)
[4] => Array
(
[t5] => test5
)
)
but I want to convert it to a single dimensional array, like the format below.
One Dimensional Array
Array (
t1 => test1
t2 => test2
t3 => test3
t4 => test4
t5 => test5
)
Please help me to do so
Hey @Karan Adhikari Simple like below one:
try something like this For your limited use case, this'll do it:
This can be more generalized for when the subarrays have many entries to this:
You can use as follows :
Where $arrayData is your DB data array and $newArray will be the result.
traverse the array and save the key value, Live Demo here.
i would recomment my way to convert all double-dimensional array to single-dimensional array.
with this script we can take keys and values to create new single-dimensional array.I hope that i was helpfull to you.
you can see the example here: Array Convert Demo
You can use this if you don't care about keeping the correct array keys
Otherwise
Check both on Sandbox
From answer on similar question