Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

please help me , im newbie , and i have a problem . My code is .

$angka=5;
$k=0;
$sum=1;
echo "<br/>";
echo "Hasil :";
echo "<br/>";
for($i=1; $i<=$angka; $i++) {
    for($j=1; $j<=$angka; $j++-6+1) {
        $k+=$sum;

        echo $k;


    }


    $k+=$sum;

    $sum*=-1;
}
?>

I want the result is like this .

15151 24242 33333 42424 51515

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
214 views
Welcome To Ask or Share your Answers For Others

1 Answer

Hello i think this answer is working.

<?php
    echo 'Expected Result:<br>';
    echo '15151 24242 33333 42424 51515';

    echo '<br>';
    echo "<br/>";
    echo "Hasil :";
    echo "<br/>";

    $start = 1;
    $angka = 5;
    $a = $angka;
    for($i=$start; $i<=$angka; $i++) {
        for($j=$start;$j<=$angka;$j=$j+2){
            echo $i;
            if($j < $angka) echo $a;
        }
        $a--;
        echo ' ';
    }
?>

Result:

Expected Result:
15151 24242 33333 42424 51515

Hasil :
15151 24242 33333 42424 51515

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...