Basic Syntax Help

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
cjconnor24
Forum Newbie
Posts: 13
Joined: Wed Oct 29, 2008 6:31 am

Basic Syntax Help

Post by cjconnor24 »

Hi all,

I have been following a tutorial on how to have an image gallery dynamically generate columns.

I have came across this line of code and i don't know what it does:

Code: Select all

$numImages = substr($row['thumb'],3) > 1 ? substr($row['thumb'],3) . ' images' : substr($row['thumb'],3) . ' image';
mainly what the ? and : do here? (i put the substr() on to trim the path!)

Any help would be appreciated!!!

Thanks,
C
sparrrow
Forum Commoner
Posts: 81
Joined: Mon Oct 20, 2008 12:22 pm

Re: Basic Syntax Help

Post by sparrrow »

That is shorthand for if ? then : else
cjconnor24
Forum Newbie
Posts: 13
Joined: Wed Oct 29, 2008 6:31 am

Re: Basic Syntax Help

Post by cjconnor24 »

oh dear :oops:

sorry about that - didn't even know there was such a thing - just getting in to php.

much appreciated!!

c
mmj
Forum Contributor
Posts: 118
Joined: Fri Oct 31, 2008 4:00 pm

Re: Basic Syntax Help

Post by mmj »

Post Reply