Jump to content

Archived

This topic is now archived and is closed to further replies.

bassplaya4string

parse error, unexpected T_DOUBLE_ARROW

Recommended Posts

anybody see anything wrong with this code?

[code]if ($score < 3){
$image1 = "<img src = 'images/0-3.jpg'>";
}
else ($score => 4 && =< 7){
$image2 = "<img src = 'images/4-7.jpg'>";
}
else ($score => 8 && =< 10){
$image3 = "<img src = 'images/8-10.jpg'>";
}[/code]

Share this post


Link to post
Share on other sites
PHP uses >= instead of =>, because => has another meaning.

[code] if ($a >= 5) { $arr = array('fred' => 5); }[/code]

Share this post


Link to post
Share on other sites
I switched them but it came back with this error now

parse error, unexpected T_IS_SMALLER_OR_EQUAL

[code]
if ($score <= 3){
$image1 = "<img src = 'images/0-3.jpg'>";
}
else if ($score >= 4 && <= 7){
$image2 = "<img src = 'images/4-7.jpg'>";
}
else ($score >= 8 && <= 10){
$image3 = "<img src = 'images/8-10.jpg'>";
}
}
}
[/code]

Share this post


Link to post
Share on other sites
[code]
if ($score <= 3){
$image1 = "<img src = 'images/0-3.jpg'>";
}
else if (($score >= 4) && ($score <= 7)){
$image2 = "<img src = 'images/4-7.jpg'>";
}
else (($score >= 8) && ($score <= 10)){
$image3 = "<img src = 'images/8-10.jpg'>";
}
[/code]

or...

[code]
switch ($score) {
  case >= 8 : $image3 = "<img src = 'images/8-10.jpg'>"; break;
  case >= 4 : $image2 = "<img src = 'images/4-7.jpg'>"; break;
  case <= 3 : $image1 = "<img src = 'images/0-3.jpg'>"; break;
}
[/code]

although i'm not sure i understand your logic here.. I mean, you have 3 different variables (image1,image2, image3) and depending on what score is, one of those 3 get changed.  Are you going to later on check which one exists or something? I suppose that's all up to you on what you're doing.  It just seemed odd to me..

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.