0

このコードのエラーを見つけるのを手伝ってくれる人はいますか? 実行しようとすると、予期しない「;」があると表示されます 10行目ですが、これがどこにあるのかわかりません。ありがとう `

$lines = array (
    0=>'Once upon a time',
    1=>'There lived a small green frog that lived',
    2=>'on a lilypad in a pond. ',
    3=>'One day a princess came along and kissed it.'
);

$max = count($lines) ;
$out = null ;
while ($i = 0; $i<$max;  $i++) {
    $opentag = '' ;
    $closetag = '' ;

    if ($i = 0) {
        $opentag = '<h1>' ;
        $closetag = '</h1>' ;
    }
    if ($i = 1 )     {
        $opentag = '<p>' ;
    }
    if ($i = ($max-1) )     {
        $closetag = '</p>' ;
    }

    $out = $opentag . $lines[$i] $closetag  ;

}
echo $out ;

?>`  
4

3 に答える 3

2

上記のコードには複数のエラーがあります。

まず、ループでfor条件を使用しwhileているため、次を使用する必要があります。

for ($i = 0; $i<$max;  $i++) {
}

次に、この行で:

$out = $opentag . $lines[$i] $closetag  ;

.と の間が$lines[$i]ありません$closetag

ifまた、ステートメントで不適切な演算子を使用しています。

==ステートメントを比較し、等しい場合は true を返し、等しくない場合は false を返します。

=左辺を右辺に合わせる

if($i = 1){}

上記は$i、値 1 に設定している間は true を返します。

于 2013-01-29T04:20:19.823 に答える
1

Seems that there are too many errors / mistakes in your code.

Firstly make it For loop instead while.

Than you missing . in below line,

$out = $opentag . $lines[$i] . $closetag;
                             ^   

Also you are doing wrong in your all conditions for it should be like,

if ($i == 0) { 

It should be == & not just =.

于 2013-01-29T04:14:44.833 に答える
0

これは間違っています :

while ($i = 0; $i<$max;  $i++) {

while 構文を確認してください。そこを利用すればいいと思いますfor

for($i = 0; $i<$max;  $i++) {
于 2013-01-29T04:17:31.213 に答える