|
|
|
|
|
|
|
![]() |
#1 |
Certified Nice Person
|
Terinary operator in PHP
Fuck me with a stick.
I have this piece of code which pulls words from flatfile databases: Code:
$sentence = ($type ? "$word1[0] $word2[0] $word3[0] $word4[0]" : "$word1[0] $word2[0] $word3[0] $word4[0] $word5[0]");
__________________
Click here to purchase a bridge I'm selling. |
![]() |
![]() |
![]() |
#2 |
a.k.a. Sparky
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
|
that statement means:
Code:
if ($type) { $sentence = "$word1[0] $word2[0] $word3[0] $word4[0]"; } else { $sentence = "$word1[0] $word2[0] $word3[0] $word4[0] $word5[0]"; }
__________________
SnapReplay.com a different way to share photos - iPhone & Android |
![]() |
![]() |
![]() |
#3 |
Certified Nice Person
|
Neat, thanks.
![]()
__________________
Click here to purchase a bridge I'm selling. |
![]() |
![]() |
![]() |
#4 |
a.k.a. Sparky
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
|
$type would need to have more than a true/false value.
you could do something like Code:
switch ($type) { case 0: $sentence = "$word1[0] $word2[0] $word3[0] $word4[0]"; break; case 1: $sentence = "$word1[0] $word2[0] $word3[0] $word4[0] $word5[0]"; break; case 2: asdfhaskdhflasjdhflashdf break; default: asdjhflasjhdfljashdflkjhasdf break; }
__________________
SnapReplay.com a different way to share photos - iPhone & Android |
![]() |
![]() |
![]() |
#5 |
Certified Nice Person
|
Woohoo! It works! Thank you.
With $type = mt_rand(0,3); it works just as I had hoped. You da man ![]()
__________________
Click here to purchase a bridge I'm selling. |
![]() |
![]() |
![]() |
#6 |
a.k.a. Sparky
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
|
nah, just one of 3.1 billion.
__________________
SnapReplay.com a different way to share photos - iPhone & Android |
![]() |
![]() |
![]() |
|
|