0

Here i have one array in that array i want to find not null values and display in frond end ,suppose in this array all key values in null means i want to display all values are null,suppose any one of the key is not null means i want to display what is that value

<?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

2
  • Your example array doesn't contain any null values but some empty strings. Commented Feb 15, 2017 at 17:19
  • can you please update your answer Commented Feb 15, 2017 at 17:19

3 Answers 3

0

If you want not empty not null array try like this

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

Check here : https://eval.in/737817

Sign up to request clarification or add additional context in comments.

Comments

0

I've forgotten to specify the third parameter to in_array.

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

This way it will tell if there is an actual null value in the array.

Comments

0

hey there you can use this :

$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 
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.