且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP数组:如何打印只数组值而不是键

更新时间:2023-02-25 14:35:00

 回声破灭('< 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);