2017-02-15 60 views
0

在這裏,我有一個數組中的一個數組我想找到在前端處不空數據並顯示,此數組中假定所有鍵值空顯示意味着我要顯示所有值都爲空,假設關鍵中的任何一個不爲空意味着我要顯示什麼是價值如何找到在PHP中沒有空值,如果條件

<?php 
$array = array('a' => '','b' => 'Kani' , 'c' => '', 'd' => 'Raja'); 

if (in_array(null, $array)) { 

    echo "There are null values."; 
}else{ 
    echo "Not Null"; 
} 
?> 

這裏關鍵的a和d不爲空,所以我想取這個關鍵值如Kani 和Raja

+0

你們的榜樣數組不包含任何'null'值,但一些空字符串。 – insertusernamehere

+0

可以請你更新你的答案 –

回答

0

如果你想不空不空數組嘗試像這樣在這裏

<?php 
    print_r(array_filter(array('a' => '','b' => 'Kani' , 'c' => '', 'd' => 'Raja'))); 
    ?> 

檢查:https://eval.in/737817

0

嘿,你可以使用這個:

$notNulvals = array(); 
$index =0; 
foreach ($array as $key => $value) { 
    if ($value) { 
     array_push($notNulvals, $value); 
     $index=1; 
    } 
} 

if ($index!=0) { 
    echo "all values are null"; 
} else { 
    echo $notNulvals; //you can display it the way you want 
} 
0

我忘了指定的第三個參數in_array。

if (in_array(null, $array, true)) { 
    echo "There are null values."; 
}else{ 
    echo "Not Null"; 
} 

這樣它會告訴數組中是否存在實際的空值。