Set multi-dimensional array by key path from array values?

前端 未结 5 1591
南笙
南笙 2020-12-10 18:38

Sorry for the terrible title, best I could think of at the time! Say I have a \'path\' array like so;

array(\'this\', \'is\', \'the\', \'path\')

5条回答
  •  独厮守ぢ
    2020-12-10 19:18

    function buildArrayFromPath( $path ) {
      $out = array();
      while( $pop = array_pop($path) ) $out = array($pop => $out);
      return $out;
    }
    

提交回复
热议问题