variables - PHP if $var null then return $var2 -


i havent been able find answer this:

my code works this:

echo ' <p> '.$test2.'</p> '; 

i want make $test2 change if null have tried following code , bunch of other , breaks page

$test2 = if(empty($price)){ return $pstatus}; 

any apprteciated

update have modified code, returns price if price empty returning nothing when should return $pstatus

so $price 625000 variable empty should return sold $pstatus variable

$price = number_format($p->meta_box->real_homes_property_price); $fimage = $p->better_featured_image->media_details->sizes->medium->source_url; $ptitle = $p->title->rendered; $pdesc = $p->excerpt->rendered; $plink = $p->link; $pstatus = $p->pure_taxonomies->{"property-status"}[0]->name; $test2 = $pstatus ? $price : $test2; 

you can inline:

$test2 = $price ? $pstatus : $test2; 

if need assign "$price" "$test2" , if there no price assign "$pstatus":

$test2 = $price ? $price : $pstatus; 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -