php中用三元函数判断数字的奇偶性的异常,请教如何解决

WBOY
Release: 2016-06-13 12:07:08
Original
2046 people have browsed it

php中用三元函数判断数字的奇偶性的错误,请问怎么解决
Parse error: syntax error, unexpected 'echo' (T_ECHO) in F:\xampp\htdocs\test\test02.php on line 26 这是错误描述,

下面是源代码:
   for($a =0;$a  //用三元运算输出,如果没有余数则是偶数,
        否则为奇数      
    echo $a %2==0?$a."是偶数"."\n":$a."是奇数"."\n"; 
 }  
?> 
------解决思路----------------------
//否则为奇数
------解决思路----------------------
for($a =0;$a  //用三元运算输出,如果没有余数则是偶数,否则为奇数      
  echo $a %2==0?$a."是偶数"."\n":$a."是奇数"."\n"; 
}

------解决思路----------------------

<br /> for($a =0;$a<10;$a++){    <br />  //用三元运算输出,如果没有余数则是偶数,<br />        //否则为奇数      <br />    echo $a%2==0?$a."是偶数"."\n":$a."是奇数"."\n"; <br /> }  <br /><br />
Copy after login


<br />0是偶数 1是奇数 2是偶数 3是奇数 4是偶数 5是奇数 6是偶数 7是奇数 8是偶数 9是奇数 <br /><br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!