0
我有一个表单域,并希望检查每个输入域是否已经存在于数据库中。将字符串连接成一个单个字符串作为变量在php中
下面是我的PHP代码:
$sql_query = "SELECT * FROM test_table";
if($result_query = $connect->query($sql_query))
{
$items = array("firstName", "lastName", "country", "phone");
//$names variable contains stored values which i've declared at the beginning
$names = array($firstName, $lastName, $country, $phone);
foreach(array_combine($items, $names) as $item => $name)
{
$array_items = "";
$check_query = "SELECT $item FROM test_table WHERE $item = '".$name."'";
$result_check_query = $connect->query($check_query);
if($row_query = $result_check_query->num_rows)
{
$array_items .= $item . ", ";
}
echo $array_items . "gettype()=> " . gettype($array_items);
echo "<br>";
}
print_r ("<br>" . $array_items);
}
从echo $array_items
结果是如下:
问题是,当我打印/回声出$array_items
外foreach
循环,只有它获得phone
我怎样才能得到所有的单个字符串作为一个,并将其分配给一个变量在PHP?
在此先感谢。
如果有与旧帖子的链接,请为我提供链接。 我不知道术语用来搜索这类问题。
你是否希望数组在末尾作为最终输出(在单独索引中包含组串输出)? –
这也会有帮助。是的,请给我看看@AlivetoDie –
你已经有答案,它也被选中 –