what does % mean after a variable

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
bayridge
Forum Newbie
Posts: 5
Joined: Wed Nov 13, 2002 7:38 pm

what does % mean after a variable

Post by bayridge »

Hi. I can't believe it's over 10 years and I still don't know nearly as much about this langhuage as I should. Problem is I only use the basics and only care that my script works. Anyway, it's been over 13 years since I was here last. Wow.

So. I'm modifying a calendar script that some guy put up someplace to show people how to make a calendar script. Anyone interested in it can go here: http://www.startutorial.com/articles/vi ... dar-in-php.

I'm going to use it on a couple of web sites for events. I just have a couple of questions maybe someone can help with. Probably simple for php programmers but I'm still in novice class and probably always will be.

What does the percent sign, number and question mark (%7?) mean at the end of a variable. For instance, $cellNumber%7?==1 and $cellNumber%7?==0 .
It's used in line number 129 on script at website below. Thanks.

http://www.startutorial.com/articles/vi ... dar-in-php
Last edited by bayridge on Fri Mar 11, 2016 3:43 pm, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: what does % mena after a variable

Post by Celauran »

bayridge
Forum Newbie
Posts: 5
Joined: Wed Nov 13, 2002 7:38 pm

Re: what does % mena after a variable

Post by bayridge »

Code: Select all

return '<li id="li-'.$this->currentDate.'" class="'.($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' ')).($cellContent==null?'mask':'').'">'.$cellContent.'</li>';
I'm still not getting it. This entire sentence makes no sense to me.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: what does % mena after a variable

Post by Christopher »

Also look at the ternary operator:

http://php.net/manual/en/language.opera ... arison.php (halfway down the page)

Note - the parens in that line are so the concatenation works on the values chosen by the ternary operations.
(#10850)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: what does % mena after a variable

Post by Celauran »

Nested ternaries are a bit of a mess to read, but it's basically setting calendar width by checking if you're at the start/end of a row by dividing by zero.
bayridge
Forum Newbie
Posts: 5
Joined: Wed Nov 13, 2002 7:38 pm

Re: what does % mean after a variable

Post by bayridge »

Okay, I'm even worse at math. This guy was writing an article on how to write a basic calendar. I got it working and made a few mods to it and still want to do some more, but it's way beyond my level of php. I was a mainframe programmer using COBOL and CICS for 25 years and retired and started doing web pages with MySQL and php that I picked up myself. I just learned enough to do simple web pages. Anyway, I think this tutorial this guy wrote is way too hard for a beginner. I'll probably just use the logic he used and start from scratch and do my own. I don't use the stuff he is like public and private and $this-> ternaries and so on, just the basic beginner stuff.

So thanks for the help and I'm glad I found this board again. I'll probably be back soon with more questions. Do you guys have a donate page or something? I don't like to keep taking and not be able to contribute cause I don't know enough.
Post Reply