How to call if condition if only one array is empty if both empty then call else condition?

if array is empty javascript
check if array has empty values php
check array is empty php
laravel check if array is empty in controller
php check if string is empty or whitespace
if array is empty python
php empty string
check if array is empty laravel

I am using CodeIgniter. I am getting the response from model and display on the controller.

Model

//some code here
return array('secondary_data'=> $result,'primary_data' =>$result2);// sending to controller
// some code here

Controller

$result=$this->Search_model->get_search_name($cust_name);//calling model    
$data['secondary_data'] = $result['secondary_data'];
$data['primary_data'] = $result['primary_data'];

print_r($data['secondary_data']);
print_r($data['primary_data']);

output

Array
(
    [0] => stdClass Object
        (
            [member_id] => 
            [customer_id] => 
            [first_name] => qwer
            [last_name] => poiu
            [email] => 
            [member_type] => 2

        )

)
Array
(
    [0] => stdClass Object
        (
            [member_id] => 1
            [customer_id] => 0011
            [first_name] => asdasd 
            [last_name] => asdasda
            [email] => bappyang68@gmail.com
            [member_type] => 1

        )

)

but sometimes I am getting empty array of print_r($data['primary_data']) because of no data. Yes, it's possible.;

but in below if condition I am checking the data count count($data) > 0 and if found empty then calling the else part.

I don't want to call else part if only one array is emply. if both array is empty then it should call else part

    if (count($data) > 0)
     {
        $data['title'] = "Search";
        $data['heading'] = "Search";
        $data['content'] = $this->load->view('search',$data,true);
        $this->load->view('dashboard/dashboard',$data);
        }
       else{
       echo "NO data available";
      }

Any idea how to do this? Thanks

Check your both array separately in or condition

if (count($data['primary_data']) > 0 || count($data['secondary_data']) > 0)
{
   $data['title'] = "Search";
   $data['heading'] = "Search";
   $data['content'] = $this->load->view('search',$data,true);
   $this->load->view('dashboard/dashboard',$data);
}else{
   echo "NO data available";
}

How to check that an object is empty in PHP?, How do you check if an array is not empty? The input array of your “Filter array” action is not an empty array, it has one element which is an empty string, so the result that your @empty() function returned is false. Please check if there is something wrong with the formula of your “Get Attendees” action.

Try this condition with OR operator

if(!empty($data['primary_data']) || !empty($data['secondary_data'])){
//One or both array have values
}else{
//Both have no values
}

How can I check whether an array is null / empty?, How do you check if a 2d array is empty? In both methods logical_test argument returns TRUE if a cell is Blank, otherwise, it returns FALSE if the cell is Not Blank. For example, you need to evaluate that if a cell is Blank, the blank value, otherwise return a value “Delivered”. In both approaches, following would be the IF formula; =IF(C2="","","Delivered") OR

You can use separate condition for both array, If one of them is not empty then apply If condition otherwise else.

if ( !empty($data['secondary_data']) || !empty($data['primary_data']) ) {
    $data['title'] = "Search";
    $data['heading'] = "Search";
    $data['content'] = $this->load->view('search',$data,true);
    $this->load->view('dashboard/dashboard',$data);
} else {
   echo "NO data available";
}

Bioinformatics Programming in Python: A Practical Course for Beginners, A Practical Course for Beginners Ruediger-Marcus Flaig extended by dividing it into three subclauses: an initializer, a condition and a step action. In FORTRAN, the where–elsewhere construct mirrors the if–else structure but refers to an array, of Otherwise do something with the first item (head) of the list, then call the  If the condition is false, it then executes the statements in the else statement block and then exits the loop. The following diagram shows the flow of the ‘if’ statement. Checking Variables. Just like the ‘if’ statement in Batch Script, the if-else can also be used for checking variables which are set in Batch Script itself.

start checking from $data then sub array

if(count($data) && (isset($data['secondary_data']) && !empty($data['secondary_data'])) || (isset($data['primary_data']) && !empty($data['primary_data']))){
      ....
    }else{
      ...
    }

Encyclopedia of Bioinformatics and Computational Biology: ABC of , The algorithm we just described is an example of iterative algorithm that realises a means of two recursive calls on as many sub-arrays of size n/2 each), and then merges condition “por”: if this holds, then the recursion goes on; else (p1⁄​4r) there is Notice, indeed, that if S is not empty, then p4r can never hold as q is​  Many programming languages have a ternary operator, which define a conditional expression. The most common usage is to make a terse simple conditional assignment statement. In other words, it offers one-line code to evaluate the first expression if the condition is true, otherwise it evaluates the second expression.

empty - Manual, A variable is considered empty if it does not exist or if its value equals FALSE . empty() Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. empty() now supports expressions, rather than only variables. I believe PHP calls __isset, and if that is true returns the result of empty on the  Function Bonus(performance, salary) If performance = 1 Then Bonus = salary * 0.1 ElseIf performance = 2 Then Bonus = salary * 0.09 ElseIf performance = 3 Then Bonus = salary * 0.07 Else Bonus = 0 End If End Function

Pro Perl, This modified version of list_files uses undef to flag the caller when no path is specified: return undef unless defined $path; #return an empty list if no path return join(',', glob the subroutine returns undef, which evaluates to false in the if statement. and both of them result in an array of one element, not an empty array:  The IF-THEN function in Excel is a powerful way to add decision making to your spreadsheets. It tests a condition to see if it's true or false and then carries out a specific set of instructions based on the results.

How to check whether an array is empty using PHP?, Using empty() Function: This function determines whether a given variable is If number of elements in array is zero, then it will display empty array. element and use condition. if ( count ( $empty_array ) == 0). echo "Array is empty" ;. else Check if an array is empty or not in JavaScript · Why to check both isset() and  Conditional operators: if, '?' Sometimes, we need to perform different actions based on different conditions. To do that, we can use the if statement and the conditional operator ? , that’s also called a “question mark” operator.

Comments
  • if(count($data) && (!empty($data['secondary_data']) || !empty($data['primary_data']))){...}else{...}
  • write condition for both array or Use loop and check
  • Your code is also working for me. upvote from my side
  • This is short and simple solution.