解析错误:语法错误,意外'否则'第10行(T_ELSE)

时间:2018-05-28 10:00:41

标签: php if-statement

有人可以就如何处理此错误给我一些指导吗?我不是程序员,所以对这类事情几乎没有任何技能/知识。但是,我热衷于学习,如果有人能给我一些指导,那真是太棒了。

Parse error: syntax error, unexpected 'else' (T_ELSE) on line 10

与此相关的代码如下:

<?php 


include 'desciptions.php';
include 'title.php';
$rand=rand(0,67);


else if($rand=='1')
    $desciptions=$d1;
    $title=$m1;

else if($rand=='2')
    $desciptions=$d2;
    $title=$m2;

else if($rand=='0')
    $desciptions=$d0;
        $title=$m0;
?>

2 个答案:

答案 0 :(得分:0)

将您的代码更改为:

<?php

include 'desciptions.php';
include 'title.php';
$rand = rand(0, 67);


if ($rand == '1') {
    $desciptions = $d1;
    $title = $m1;
} elseif ($rand == '2') {
    $desciptions = $d2;
    $title = $m2;
} elseif ($rand == '0') {
    $desciptions = $d0;
    $title = $m0;
}
?>

答案 1 :(得分:0)

删除第一个else,添加{}并删除标记:

<?php 

include 'desciptions.php';
include 'title.php';
$rand=rand(0,67);

if($rand == 1) {
    $desciptions = $d1;
    $title = $m1;
} else if($rand == 2) {
    $desciptions = $d2;
    $title = $m2;
} else if($rand == 0) {
    $desciptions = $d0;
    $title = $m0;
}
?>

也可以将desciptions修复为descriptions