Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
221 views
in Technique[技术] by (71.8m points)

Print Looping for dynamic row php

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

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

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...