0
每当我试图根据来自SQL数据库的数据显示数组的内容时,输出总是以“Array”作为前缀。无论我使用echo,print_r(),var_dump()还是其他方法都无关紧要。下面的代码。任何想法大大收到!从数组中获取数据的问题
$prefix1 = '';
$tasks = array($product, $service, $order, $social, $competition, $dataOther);
foreach ($tasks as $task) {
if ($task == '') {
unset($task);
} else {
$tasks .= $prefix1 . '' . $task . '';
$prefix1 = ', ';
}
}
echo $tasks;
输出 - “阵”后面的$内容的任务
编辑:我不能使用implode(', ', $tasks)
因为每个输入端(即$product
,$service
等)可能是空白,因此,结果将是“,,”在地方。
希望更清楚。
你想做什么?? $ tasks。= $ prefix1。 ''。 $任务。 '';' –
您正在覆盖循环中的数组,并在将字符串添加到字符串时将其转换为字符串。你应该使用不同的名字。 – jeroen
'$ tasks'是一个数组,或者至少在你运行这个代码之前。你不能'echo'一个数组 – RiggsFolly