好的,我有这个
$eng[] = "All";
$eng[] = "engine_Sigma";
$eng[] = "engine_K-Series";
$eng[] = "engine_Duratec";
$eng[] = "engine_Suzuki";
$eng[] = "engine_Vauxhall";
$eng[] = "engine_Crossflow";
do {
$enginetype = explode(":", $items['engineid']);
foreach ($enginetype as $key) {
echo "$items[wsiid] - $items[code] - $items[incvat] - $eng[$key] <br>
";
}
} while ($items = mysqli_fetch_assoc($itemsq));
现在不是回显每个值的实例,而是要将foreach循环中显示的所有值分配给单个变量$ test,然后我可以在以后回显
我一直在尝试最后一小时,接近击打键盘。 任何帮助都会很棒。感谢
** ADDED **
因此,数据库查询将为表中的第1行返回值1:3:6 这意味着它应该回应engine_Sigma engine_Duratec engine_Crossflow
表中的第2行的值为2,因此只会回显engine_K-Series
表中的第3行的值为1:2:5:6,它将回显engine_Sigma engine_K-Series engine_Vauxhall engine_Crossflow 希望能更好地解释它 我希望将值分配给我稍后可以使用的变量,而不仅仅是回显foreach中的代码
我也想要它 $ var =“engine_Sigma engine_K-Series engine_Vauxhall engine_Crossflow”
答案 0 :(得分:0)
试试这个
$test=""; //Set variable to null
do {
$enginetype = explode(":", $items['engineid']);
foreach ($enginetype as $key) {
$test .="$items[wsiid] - $items[code] - $items[incvat] - $eng[$key] <br>
";
}
} while ($items = mysqli_fetch_assoc($itemsq));
echo $test; //display test
答案 1 :(得分:0)
您必须在范围外声明变量。如下所示:
$values = [];
do {
$enginetype = explode(":", $items['engineid']);
foreach ($enginetype as $key) {
$values[] = "$items[wsiid] - $items[code] - $items[incvat] - $eng[$key]";
}
} while ($items = mysqli_fetch_assoc($itemsq));
// Somewhere later
foreach($values as $value) {
// Do stuff.
}