2017-05-29 3 views
0

wie zu überprüfen, mysql NULL Spalten mit PHP variabel?php mysql wie zu prüfen, NULL-Spalte mit PHP

meine Zeilen Tabelle (Beispiel):

1 ---- james ------ italy

2 ---- joyee ------ NULL

meine Array von Tisch holen:

$rows[0] = array('name' => 'james', 'country' => 'italy'); 
$rows[1] = array('name' => 'joyee', 'country' => NULL); 

aber mein Problem:

, wie Sie überprüfen NULL-Array Element:

foreach($rows as $row) { 

    if ($row['country'] == NULL) echo "country is null"; // not working 
    if ($row['country'] == '') echo "country is null"; // not working 
    if (is_null($row['country'])) echo "country is null"; // not working 
    if (empty($row['country'])) echo "country is null"; // not working 
    // what is solution? how to check null? 

} 

Update (Var_dump):

'country' => null 
+0

Versuchen Sie Null in Kleinbuchstaben. –

+0

können Sie Ihren Beitrag mit 'var_dump ($ rows [1])' 'aktualisieren? –

+1

Mögliches Duplikat von [PHP Check für NULL] (https://stackoverflow.com/questions/1576243/php-check-for-null) –

Antwort

4

Verwendung is_null oder === Operator.

is_null($row['country']) 
+0

ja ist wahr. Danke – grizzly