how to create a multidimensional array with the 2nd nesting. I tried it this way, but it turns out a bit is not what you need

$overall = array(); for ($i=0;$i<3;$i++){ for ($j=0;$j<5;$j++){ $overall[$i][] = $j; } } 

Turns out

 array(3) { ["1"]=> array(6) { [0]=> string(3) "1" [1]=> string(5) "2" [2]=> string(6) "3" [3]=> string(6) "4" [4]=> string(6) "5" } ["2"]=> array(6) { [0]=> string(3) "1 [1]=> string(3) "2" [2]=> string(3) "3" [3]=> string(3) "4" [4]=> string(3) "5" } ["3"]=> array(6) { [0]=> string(18) "1" [1]=> string(18) "2" [2]=> string(18) "3" [3]=> string(18) "4" [4]=> string(18) "5" } } 

I would like to set the name of the keys of the internal array in a loop, what would be the type

  array(3) { ["1"]=> array(6) { [задано в цикле]=> string(3) "1" [задано в цикле]=> string(5) "2" [задано в цикле]=> string(6) "3" [задано в цикле]=> string(6) "4" [задано в цикле]=> string(6) "5" } ["2"]=> ..... 
  • one
    so you can not do. The words "set in a loop" are the key of an associative array, but they (the keys) must be unique ... - cyadvert

1 answer 1

dirk, Do you want the key phrase to be "set in a loop"? Or do you want to create a key for some pattern? For example:

 $overall = array(); for ($i=0;$i<3;$i++) { for ($j=0;$j<5;$j++) { $key = "key" . $j $overall[$i][$key] = $j; } }