-1

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);
  } 
0

4 Answers 4

1

You have to use isset()

$prices = array(); 

if(isset($property_type['price1'])) array_push($prices, $property_type['price1']);
Sign up to request clarification or add additional context in comments.

2 Comments

still giving error....it giving error on that line " $price1=$property_type['price1']; "
thank u soo much...its fine now
1

Try This

$prices=array();

if (isset($property_type['price1']) && $property_type['price1'] !== null) {

  $price1=$property_type['price1'];
  array_push($prices, $price1);

}

1 Comment

thank u soo much bro..its fine now
1

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']);
}

1 Comment

thanx bro...i exactly did that...now its working fine
1

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);
    }
}

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.