![]() |
Using ISSET()...How does this line of code work?
I got the code below from PHP: Hypertext Preprocessor, under the ISSET() topic. It was a "contribution" to the subject from a reader, and it did not have any accompanying comments.
It looks interesting, but can anyone explain to a person with little experience (such as I) how it works? PHP Code:
Dave |
There's actually a really good explanation of this where it was discussed recently in another thread, here:
http://www.talkphp.com/general/2943-...html#post15515 It's called the ternary operator, and aside from the explanation you'll read above, it's basically checking to see if $var is set, and if it has a value. If it does, it's reassigning the value back to itself ($var to $var), and if not, it's assigning a new value (the string 'new value') to $var. -m |
...so basically, leaving the tech terms out, it works like an if-else statement (not only works, but it is exactly that). The following statement:
PHP Code:
PHP Code:
|
Thanks for info on the ternary operator
Thanks, delayedInsanity & Xenon, for the pointers.
I studied the recommended thread, plus I read some other sources, so I think I have quite a good introduction to this structure. It may be awhile, however, before I start using it on a regular basis...:-) Dave |
It may not be, you'd be surprised... I find it extremely handy to have on hand, but then again I'm all about shorthand. A lot of my code will do things like;
PHP Code:
PHP Code:
PHP Code:
|
Addendum: I realize the above example could be shortened to
PHP Code:
-m |
2015 will be my PHP year to shine...
That's probably because you "read" PHP in almost the same way that you would read a page of text. That is, you really don't have to think about what the letters and words mean individually, they all meld together "automatically" into meaning.
Probably, you can "think" in PHP, much as you might think in a foreign language after becoming very proficient in day-to-day usage. I'm a l-o-o-o-ng way from there. But one of these days, I'd say 2015 or so, I'll start seeing the pieces begin to fit together...8-) Dave |
Quote:
|
OOP burns my eyes...
I'm so far away from OOP that I can't even see it with binoculars *!*
|
Quit thinking that way. I just started doing all this back in ... february? march... or something... whenever I joined here. I jumped right into OOP because I wanted to understand it, I'm not kidding you, because I liked the look of $this-> variables. It's only taken four months and I think I've gotten a fairly good grasp on the basics of things - if you want to learn something, just go for it, you'd be surprised what you're capable of!
*gets off the soapbox* -m |
Thanks for the encouragement! Yeah, you're right. As they say, the race belongs not to the swift, but to those who keep on running. (Makes for a neat saying, anyway! :-))
Dave |
| All times are GMT. The time now is 11:41 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0