php create multidimensional array from flat one

后端 未结 5 2030
时光说笑
时光说笑 2020-12-18 11:21

I have an array like this:

 \'foo\', 1 => \'bar\', ..., x => \'foobar\' );
?>

What is the fas

5条回答
  •  借酒劲吻你
    2020-12-18 12:03

    What exactly are you trying to do? So many arrays of size 1 seems a bit silly.

    you probably want to use foreach loop(s) with a key=>value pair

    foreach ($array as $k=>$v) {
      print "key: $k  value: $v";
    }
    

    You could do something like this to achieve the array you asked for:

    $newArray = array();
    for ($i=count($array)-1; $i>=0; $i--) {
      $newArray = array($newArray[$i]=>$newArray);
    }
    

提交回复
热议问题