I have an associative array that is many levels deep. I want to convert it to an indexed array (i.e. remove the key names). I don't want to flatten it; I want it to remain a nested array with all of the values intact. What's the best way to accomplish this?
Dani
4,084
The Queen of DaniWeb
Administrator
Featured Poster
Premium Member
Recommended Answers
Jump to PostI quickly put together this recursion function.
function assoc2indexedMulti($arr) { // initialize destination indexed array $indArr = array(); // loop through source foreach($arr as $val) { // if the element is array call the recursion if(is_array($val)) { $indArr[] = assoc2indexedMulti($val); // else add the value to destination …
All 3 Replies
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
broj1
356
Humble servant
Featured Poster
Dani
4,084
The Queen of DaniWeb
Administrator
Featured Poster
Premium Member
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.