gpt4 book ai didi

php - 在php中获取变量值

转载 作者:搜寻专家 更新时间:2023-10-31 20:46:43 25 4
gpt4 key购买 nike

我有变量 $CV1, $CV2, $CV3 ...如何在循环中获取这些变量的值PHP?下面是我的代码

$CV1=$fetch->Custom_field1;
$CV2=$fetch->Custom_field2;
$CV3=$fetch->Custom_field3;
$CV4=$fetch->Custom_field4;
$query=mysql_query("select * from customfields where CustomField like '%Invoice%' and CustomLabel != ''");
while($get=mysql_fetch_object($query))
{
$i++;
$Label=$get->CustomLabel;
$CFV='$CV'.$i;
echo "<tr><td>$Label</td><td><input type='text' name='custom_field$i' value='$CFV'></td></tr>";
}

但不是获取 $CV1 的值,而是 $CV2。我将变量名本身作为输出。 $CV1$CV2

最佳答案

使用 array()而不是命名变量。

$CV[1] = $fetch->Custom_field1;
$CV[2] = $fetch->Custom_field2;

然后以这种方式获取您的值(value):

$CFV = $CV[$i];

此外,不要忘记初始化 $i

关于php - 在php中获取变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12405897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com