This article to share the content is how to implement PHP string conversion array, as a new PHP programmer's first reaction is Lenovo to explode (), implode () these two functions. The new one is also used to convert the function inside the array. has a certain reference value, the need for friends can refer to
con[1]=28&selt[1]=1&con[2]=29&selt[2]=4&con[3]=26&selt[3]=4&con[4]=30&selt[4]=2 &con[5]=4&selt[5]=1&con[6]=11&con[7]=12
The above is the user needs to convert to PHP array string; The following is a new PHP conversion code provided
<?php$str = ' con[1]=28&selt[1]=1&con[2]=29&selt[2]=4&con[3]=26&selt[3]=4&con[4]=30 &selt[4]=2&con[5]=4&selt[5]=1&con[6]=11&con[7]=12 '; $arr = Explode (' & ', $str); $arr 2 = Array ( ), foreach ($arr as $k + $v) {$arr = explode (' = ', $v); $arr 2[$k] = $arr [1];} Print_r ($arr 2);? >//output Array ([0] = [1] = 1 [2] = [3] = 4 [4] = [5] = 4 [6] = 3 0 [7] = 2 [8] = 4 [9] = 1 [Ten] = [one] = 12)//Second <?PHP$STR = ' con[1]=28&selt[1 ]=1&con[2]=29&selt[2]=4&con[3]=26&selt[3]=4&con[4]=30&selt[4]=2&con[5]=4&selt[ 5]=1&con[6]=11&con[7]=12 '; $arr = Explode (' & ', $str); $arr 2 = Array (); foreach ($arr as $k + = $v) {$arr = E Xplode (' = ', $v); $arr 2[$arr [0]] = $arr [1];} Print_r ($arr 2);? >//output Array ([con[1]] [[selt[1]] + 1 [con[2]] [selt[2]] = 4 [con[3]] = 26 [Selt[3]] + 4 [con[4]] [[selt[4]] = 2 [con[5]] [4] [selt[5]] + 1 [con[6]] = [con[ 7]] = 12)
The new PHP code can also solve the problem of string conversion to an array. Finally, Phper netizens should find the PARSE_STR () function on the manual to convert the string into a PHP array; here's a description of the PARSE_STR () function to make a good impression in your mind.
The Parse_str () function parses the query string into a variable.
Parse_str (String,array) string: strings to be converted; array: returns to an array, overwriting a variable with the same name if no array is set