In this simple loop, how do the variables in the inside write? It's simple, I'm a novice, I don't know how to write.
for ($k =1; $k <4; $k + +) {
$blName _. $k = ' Hello '. $k;
}
I want to put this $blname_1, the following number 1 is the increment effect, that is: $blName _1, $blName _2, $blName _3, with variable loop instead, how to write it?
------Solution--------------------
for ($k =1; $k <4; $k + +) {
$varname = ' blname_ '. $k;
${$varname} = ' Hello '. $k;
}
Because $varname = ' blname_1 ' so $ $varname = $blName _1;
Generally not, this should be done with an array of
PHP Code
http://www.php.net/manual/zh/language.variables.variable.php
------Solution--------------------
PHP Code
for ($k =1; $k <4; $k + +) {${"blname_{$k}"} = ' Hello '. $k;
------Solution--------------------
PHP code
$arr =array (); for ($k =1; $k <4; $k + +) {Array_push ($arr, ' hello '. $k);} List ($blName _1, $blName _2, $blName _3) = $arr;
------Solution--------------------
$var = Array ();
for ($k =1; $k <4; $k + +) {
$var [] = ' hello '. $k;
}
Print_r ($var);
Output
Array (
[0] = ' Hello 1 ';
[1] = ' Hello 2 ';
[2] = ' Hello 3 ';
)
//Take the value $var [1] and the value is ' Hello 2 '.
Read more manuals for good http://www.php.net/manual/zh/language.types.array.php
------solution--------------------
${"Blname$k" } = ' Hello '. $k;
PHP recommended syntax
$varname = ' blname ';
for ($k =1; $k <4; $k + +) {
$blName = $varname. $k;
$ $blName = ' Hello '. $k;
}
What do you mean by enclosing a variable with {}?
${$varname}
and ${"blname_{$k}"}
curly braces treat the enclosed part as a whole