skip to Main Content

Sometimes live server throws that error.It working fine in localhost while giving this error in live server.It happens sometimes not everytime.anyone please tell me the reason and solution.

here is the code where i am getting error…

 $prices=array();
  $price1=$property_type['price1'];
  if (!empty($price1)) {
  array_push($prices, $price1);
  } 

4

Answers


  1. You have to use isset()

    $prices = array(); 
    
    if(isset($property_type['price1'])) array_push($prices, $property_type['price1']);
    
    Login or Signup to reply.
  2. Try This

    $prices=array();
    
    if (isset($property_type['price1']) && $property_type['price1'] !== null) {
    
      $price1=$property_type['price1'];
      array_push($prices, $price1);
    
    }
    
    Login or Signup to reply.
  3. You should not assign to $price1 without knowing whether $property_type[‘price1’] is empty or nonempty. First, you should query whether $property_type[‘price1’] is empty or nonempty.

    you can code:

    $prices=array();
    if(!empty($property_type['price1'])){
     array_push($prices, $property_type['price1']);
    }
    
    Login or Signup to reply.
  4. This error could be triggered if $property_type['price1'] is null or not set. Make sure it is set before trying to access it as an array element

    $prices = array();
    if (isset($property_type['price1'])) {
        $price1 = $property_type['price1'];
        if (!empty($price1)) {
            array_push($prices, $price1);
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search