Php needs an array to dynamically generate array elements, but the elements in the array are not fixed. Therefore, we need to generate the elements of the array in advance and then create an array, as a result, the generated element becomes an element of the subsequently created array. The code is as follows: for ($ i0; $ I & lt; 100; $ I ++) {$ ary. $ ay. & quot; & gt; & quot ;. $ as; element} $ dataarray ($ ary); php dynamically generates array elements
Now we need an array, but the elements in the array are not fixed, so we will generate the elements of the array in advance, and then create an array, as a result, the generated element becomes an element of the subsequently created array. The code is as follows:
For ($ I = 0; $ I <= 100; $ I ++ ){
$ Ary. = $ ay. "=>". $ as; // element
}
$ Data = array ($ ary); // The created array
The format I want is as follows. $ data = array ('a' => 1, 'B' = 2, 'C' => 3); however, it is impossible to put the generated elements in it, enter the generated elements, copy them, and put them in.
I don't know what the problem is. please help me solve it!
------ Solution --------------------
For ($ I = 0; $ I <= 100; $ I ++ ){
$ Ary. = $ ay. "=>". $ as; // element
}
$ Data = array ($ ary); // The created array
This statement is incorrect. when creating an array, array ($ list );
$ List: this is a list, not a string. you can create only one element in this way.
------ Solution --------------------
To read this reply, log on to or register CSDN!
------ Solution --------------------
PHP code
$ Arr = array (); for ($ I = 0; $ I <10; $ I ++) $ arr [] = $ I * $ I;