如何找到php中的非空值并在if条件下显示
How to find the not null values in php and display in if condition
这里我在那个数组中有一个数组我想找到 not null 值并在前端显示,假设在这个数组中所有键值都在 null 表示我想显示所有值为空,假设任何一个键不为空表示我想显示那个值是什么
<?php
$array = array('a' => '','b' => 'Kani' , 'c' => '', 'd' => 'Raja');
if (in_array(null, $array)) {
echo "There are null values.";
}else{
echo "Not Null";
}
?>
Here key a and d is not null so i want take this key value like Kani
and Raja
嘿,你可以使用这个:
$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
}
我忘记指定第三个参数给in_array。
if (in_array(null, $array, true)) {
echo "There are null values.";
}else{
echo "Not Null";
}
这样它会判断数组中是否存在实际的空值。
如果你想要非空非空数组试试这样
<?php
print_r(array_filter(array('a' => '','b' => 'Kani' , 'c' => '', 'd' => 'Raja')));
?>
在此处查看:https://eval.in/737817
这里我在那个数组中有一个数组我想找到 not null 值并在前端显示,假设在这个数组中所有键值都在 null 表示我想显示所有值为空,假设任何一个键不为空表示我想显示那个值是什么
<?php
$array = array('a' => '','b' => 'Kani' , 'c' => '', 'd' => 'Raja');
if (in_array(null, $array)) {
echo "There are null values.";
}else{
echo "Not Null";
}
?>
Here key a and d is not null so i want take this key value like Kani and Raja
嘿,你可以使用这个:
$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
}
我忘记指定第三个参数给in_array。
if (in_array(null, $array, true)) {
echo "There are null values.";
}else{
echo "Not Null";
}
这样它会判断数组中是否存在实际的空值。
如果你想要非空非空数组试试这样
<?php
print_r(array_filter(array('a' => '','b' => 'Kani' , 'c' => '', 'd' => 'Raja')));
?>
在此处查看:https://eval.in/737817