Check if value is null or empty

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rbpd5015
Forum Newbie
Posts: 8
Joined: Fri Nov 25, 2005 10:51 pm

Check if value is null or empty

Post 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
Last edited by rbpd5015 on Mon Nov 28, 2005 10:38 am, edited 1 time in total.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
Post Reply