2013-07-25 38 views
0

我有一個數組沾到var_dump($array)的情況下的附加組件:

array(1) { [""]=> NULL } 

如何能我檢查這是真的還是假的? 如果數組被設置,它將得到例如

array(1) { ["test"]=> string(2) "test" } 

我試圖

if ($array == NULL) 
if ($array[""] == NULL) 
if ($array[""] == "NULL") 
if ($array == "NULL") 
+0

你已經試過了什麼? – DevlshOne

+0

if((count($ array)== 1)&&!$ array [「」]) – elnabo

+0

你是什麼意思*檢查它是真是假* –

回答

2

「」作爲數組索引是有點嚇人......

因爲$數組[0]作爲第一個元素都不行,你可以試試這個弄清楚,如果數組節點是空的:

$fillCount = 0; 
foreach ($arrData as $key => $value) 
{ 
    if (!is_null($value)) $fillCount++; 
} 

if ($fillCount <= 0) 
{ 
    // nothing useful in the array 
} 
else 
{ 
    // useful content in the array 
} 
+0

謝謝你,這工作 –

1

如果你的意思是檢查,如果值爲null或不是你可以使用空:

if(empty($array[""])) 
     //element is null 
else 
     //element is not null 

肯定數組不爲空,因爲它有一個元素(數組(1))