Page 1 of 1

Check if value is null or empty

Posted: Mon Nov 28, 2005 10:31 am
by rbpd5015
I have this piece of code

This is stats for a american football program

Code: Select all

$py = ($py > 0) ? $yds-$py : $yds;
PY is for Previous Yards and YDS is yard this week

What if a Running Back has -3 yards in week 1 since he isnt >0 it will never regester correctly. What could work?

Dont I need to see if it is null or empty.

Matt

Posted: Mon Nov 28, 2005 10:37 am
by Burrito
well if you don't know that they will have some previous yards, you could use isset() to determine if the $py variable is set. Obviously since your'e the one setting it, you should know this beforehand anyway. In which case you check to see if they have any previous yards and if not, set it to 0. You will also need to modify your ternary operator to check the condition to make sure the $py var is set vs greater than 0.