I have this array structure which i am pulling from a database.
As you can see in each nested array there is a key UID. Im just wondering if it would be possible to split these up so that within the first nested array the two arrays with uid 22 are grouped together, and then the 23s are put together and so forth.
Array
(
[0] => Array
(
[0] => Array
(
[id] => 157
[uid] => 22
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 9593
[size] => 1024x768
)
[1] => Array
(
[id] => 158
[uid] => 22
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 9593
[size] => 1280x1024
)
[2] => Array
(
[id] => 166
[uid] => 23
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 9764
[size] => 1024x768
)
[3] => Array
(
[id] => 167
[uid] => 23
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] =>; 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 9764
[size] => 1280x1024
)
[4] => Array
(
[id] => 193
[uid] => 26
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 1660
[size] => 1024x768
)
[5] => Array
(
[id] => 194
[uid] => 26
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 1660
[size] => 1280x1024
)
)
[1] => Array
(
[0] => Array
(
[id] => 157
[uid] => 22
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 9593
[size] => 1024x768
)
[1] => Array
(
[id] => 158
[uid] => 22
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 9593
[size] => 1280x1024
)
[2] => Array
(
[id] => 166
[uid] => 23
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 9764
[size] => 1024x768
)
[3] => Array
(
[id] => 167
[uid] => 23
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 9764
[size] => 1280x1024
)
[4] => Array
(
[id] => 200
[uid] => 26
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 1660
[size] => 2560x1440
)
[5] => Array
(
[id] => 201
[uid] => 26
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 1660
[size] => 960x640
)
)
)
This is what i am aiming for:
Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
[id] => 157
[uid] => 22
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 9593
[size] => 1024x768
)
[1] => Array
(
[id] => 158
[uid] => 22
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 9593
[size] => 1280x1024
)
)
[1] => Array
(
[0] => Array
(
[id] => 166
[uid] => 23
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] => 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 9764
[size] => 1024x768
)
[1] => Array
(
[id] => 167
[uid] => 23
[name] => Lexmoto ZSX 125
[models] => #ZS125-48A#
[cmd] =>; 1
[lm] => 1
[pm] => 0
[active] => 1
[downloads] => 9764
[size] => 1280x1024
)
)
)
)
I dont know if this would be possible or not, i am stumped at how i could achieve this.
foreach
loop on the array and put them together as you want in a new one. Advice: for situations like this if you usevar_export()
instead ofvar_dump()
orprint_r()
other users can copy the array easily to test/develop an answer for you xD – aleation 19 hours ago