PHP变量 - 并置的变量名 [英] PHP Variables - Concatenate variable name
本文介绍了PHP变量 - 并置的变量名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个循环PHP:
for ($counter=0,$counter<=67,$counter++){
echo $counter;
$check="some value";
}
什么,我想acheive是使用for循环变量并将其附加到另一个变量的名称。
what I am trying to acheive is use the for loop variable and append it to the name of another variable.
Bascially,我想PHP的输出是每一行如下:
Bascially, I want the PHP output to be as follows for each row
1
$check1="some value"
2
$check2="some value"
3
$check3="some value"
4
$check4="some value"
etc etc
我如何达致这?我失去了一些东西明显?
How can I acheive this? am I missing something obvious?
我曾尝试 $检查。$柜台=一些价值
,但失败。
什么建议吗?
Thans一如既往地
Thans as always,
推荐答案
有关可变变量是:
${"check" . $counter} = "some value";
然而,我非常不鼓励这一点。你想完成能最有可能使用阵列更优雅解决什么。用法示例:
However, I highly discourage this. What you're trying to accomplish can most likely be solved more elegantly by using arrays. Example usage:
// Setting values
$check = array();
for ($counter=0,$counter<=67,$counter++){
echo $counter;
$check[] = "some value";
}
// Iterating through the values
foreach($check as $value)
{
echo $value;
}
这篇关于PHP变量 - 并置的变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文