![]() |
Terinary operator in PHP
Fuck me with a stick.
I have this piece of code which pulls words from flatfile databases: Code:
$sentence = ($type ? |
that statement means:
Code:
if ($type) { |
Neat, thanks. ;) A little more understandable for a guy like me. I swapped out the original code with yours and all worked well. Here is where I run into trouble though. I'd like to be able to add a third expression, but can't figure out how. My top secret script 'chooses' which sentence to to create from the two current expressions. Is it possible to add a third expression to that? It works fine as is, but could be made better in the future if I was able to add more junk.
|
$type would need to have more than a true/false value.
you could do something like Code:
switch ($type) { |
Woohoo! It works! Thank you.
With $type = mt_rand(0,3); it works just as I had hoped. You da man |thumb |
nah, just one of 3.1 billion.
|
All times are GMT -4. The time now is 12:31 PM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc