Convert multidimensional array into single array

后端 未结 20 1909
时光取名叫无心
时光取名叫无心 2020-11-22 10:39

I have an array which is multidimensional for no reason

/* This is how my array is currently */
Array
(
[0] => Array
    (
        [0] => Array
                


        
20条回答
  •  再見小時候
    2020-11-22 11:20

    I've written a complement to the accepted answer. In case someone, like myself need a prefixed version of the keys, this can be helpful.

    Array
    (
        [root] => Array
            (
                [url] => http://localhost/misc/markia
            )
    
    )
    
    Array
    (
        [root.url] => http://localhost/misc/markia
    )
    
     $value) {
        if (is_array($value)) {
          $result = array_merge($result, flattenOptions($value, $key));
        }
        else {
          $result[$old . '.' . $key] = $value;
        }
      }
      return $result;
    }
    

提交回复
热议问题