PHP数组:如何打印只数组值而不是键 [英] php arrays: how to print only array values but not keys
本文介绍了PHP数组:如何打印只数组值而不是键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这code遍历一个MySQL表并打印出空/空字段。然而,它打印出数组值和这样的键
阵列(
[0] =>在输入栏DOB,1是空/空
[1] =>在输入栏USER_NAME7是空/空
)
我如何打印这样的事情在进入1场DOB为空/空
$ SQL =SELECT * FROM用户信息;
$解析度=的mysql_query($的SQL);
而($行= mysql_fetch_array($水库)){
的foreach($行为$关键=> $场){
如果(空($场)){
$ emptyFields [] =的sprintf('在进入%d个田%s是空/空',$键,$行['用户id']);
}
}
}
的print_r($ emptyFields);
解决方案
回声破灭('< BR>',$ emptyFields);
This code loops through a mysql table and prints out empty/null fields. It however prints the array values and the keys like this
Array (
[0] => Field "dob" on entry "1" is empty/null
[1] => Field "user_name" on entry "7" is empty/null
)
How do I print something like this field "dob" on entry "1" is empty/null
$sql = "SELECT * FROM userinfo";
$res = mysql_query($sql);
while ($row = mysql_fetch_array($res)) {
foreach($row as $key => $field) {
if(empty($field)) {
$emptyFields[] = sprintf('Field "%s" on entry "%d" is empty/null', $key, $row['userid']);
}
}
}
print_r($emptyFields);
解决方案
echo implode('<br>', $emptyFields);
这篇关于PHP数组:如何打印只数组值而不是键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文