用php输出
1
121
12321
1234321
12321
121
1

解决方案 »

  1.   


    <?php
    $max = isset($_GET['t']) ? $_GET['t'] : 4;
    $row = 1;
    $row_break = true;
    $str='';
    while (true) {
        $b = true;
        $i = 1;
        while (true) {
            $str.=$i;
            if ($i >= $row)
                $b = false;
            $b ? $i++ : $i--;
            if (!$i){
                echo $str. '<br />';
                break;
            }
        }
        if ($row >= $max)
            $row_break = false;
        $row_break ? $row++ : $row--;
        $str='';
        if (!$row)
            break;
    }
      

  2.   

    <?php
    $max = isset($_GET['t'])&& is_numeric($_GET['t']) ? $_GET['t'] : 4;
    $current_row=$max-1;
    while (true) {
        $row=$max-abs($current_row--);
        $col=$row-1;
        $str='';
        while (true) {
            $str.=$row-abs($col--);
            if ($col== -$row){
                echo $str. '<br />';
                break;
            }
        }
        if ($current_row == -$max)
            break;
    }
    再简化一下。
      

  3.   

    这不是php问题,是编程基础问题,LZ是来送分的吧
      

  4.   

    嗯 之所以奇怪是 人家测试个for输出,有这么奇葩的代码...$max = isset($_GET['t'])&& is_numeric($_GET['t']) ? $_GET['t'] : 4;
      

  5.   

    php代码for ($index = 1; $index < 5; $index++) {
        for ($indexl = 1; $indexl <= $index; $indexl++) {
            echo $indexl;
        }
        for ($indexl = $index-1; $indexl >0 ; $indexl--) {
            echo $indexl;
        }
        echo '<br>';
    }
    for ($index = 5; $index > 0; $index--) {
        for ($indexl = 1; $indexl <= $index; $indexl++) {
            echo $indexl;
        }
        for ($indexl = $index-1; $indexl >0 ; $indexl--) {
            echo $indexl;
        }
        echo '<br>';
    }
    html结果页面1
    121
    12321
    1234321
    123454321
    1234321
    12321
    121
    1
      

  6.   

    汗 第2个for写差了for ($index = 1; $index < 5; $index++) {
        for ($indexl = 1; $indexl <= $index; $indexl++) {
            echo $indexl;
        }
        for ($indexl = $index-1; $indexl >0 ; $indexl--) {
            echo $indexl;
        }
        echo '<br>';
    }
    for ($index = 3; $index > 0; $index--) {
        for ($indexl = 1; $indexl <= $index; $indexl++) {
            echo $indexl;
        }
        for ($indexl = $index-1; $indexl >0 ; $indexl--) {
            echo $indexl;
        }
        echo '<br>';
    }1
    121
    12321
    1234321
    12321
    121
    1
      

  7.   

    for ($index = 5; $index > 0; $index--) {
    红色数字 改成 3 汗
      

  8.   

    我也来个最简单的$sum = 5;
    for($i=1; $i<=$sum; $i++) {
        for($k=1; $k<=$sum; $k++) {
            echo $k;
            if($k == $i) break;
        }
        for($k=$i-1; $k>=1; $k--) {
            if($i == $k) break;
            echo $k;
        }
        echo '<br/>';
    }
    /**
    输出结果:
    1
    121
    12321
    1234321
    123454321
    */
      

  9.   


    $len = 9;
    for($i=1,$n=2*$len;$i<$n;++$i){
    $arr[] = $i == 1 || $i == $n-1 ? '1' : join('',range(1, $len-abs($i-$len))) . join('',range($len-1-abs($i-$len), 1));
    }
    echo join("\n", $arr);
    /**
    1
    121
    12321
    1234321
    123454321
    12345654321
    1234567654321
    123456787654321
    12345678987654321
    123456787654321
    1234567654321
    12345654321
    123454321
    1234321
    12321
    121
    1
    /**/
      

  10.   

    总算勾引出来一点精彩的代码了,range函数的用法,秒哇。
      

  11.   

    <?php
    $n = $_REQUEST['n'] - 1;
    if ($n < 1) $n = 1;
    if ($n > 8) $n = 8;
    ?>
    <?php
    for ($i = -$n; $i <= $n; $i++) {
    for ($j = abs($i) - $n; $j <= $n - abs($i); $j++) {
    printf('%d', $n - abs($i) - abs($j) + 1);
    }
    echo '<br>';
    }
    ?>
    委琐流
      

  12.   

    小弟艰苦的写了半天...准备学习楼上的!<?php
    $b=4;
    for($i=1;$i<=$b;$i++)
    {
    $a=$i;
    for($g=1;$g<=$a;$g++)
    {
    echo $g;
    }
    for ($h=$i-1;$h>0;$h--)
    {
    echo $h;
    }
    echo "<br>";
    }
    for($i=$b-1;$i>=1;$i--)
    {
    $a=$i;
    for($g=1;$g<=$a;$g++)
    {
    echo $g;
    }
    for ($h=$i-1;$h>0;$h--)
    {
    echo $h;
    }
    echo"<br>";
    }
    ?>
      

  13.   

    echo '1'
    echo '121'
    echo '12321'
    echo '1234321'
    echo '123454321'
    echo '12345654321'
    echo '1234567654321'
    echo '123456787654321'
    echo '12345678987654321'
    echo '123456787654321'
    echo '1234567654321'
    echo '12345654321'
    echo '123454321'
    echo '1234321'
    echo '12321'
    echo '121'
    echo '1'我这个地球人都知道
      

  14.   

    不就比简单额...咱也会.$i = 1;
    $j = 2;
    $k = 3;
    $f = 4;echo $i.'</br>';
    echo $i.$j.$i .'</br>';
    echo $i.$j.$k.$j.$i.'</br>';
    echo $i.$j.$k.$f.$k.$j.$i.'</br>';
    echo $i.$j.$k.$j.$i.'</br>';
    echo $i.$j.$i .'</br>';
    echo $i.'</br>';
      

  15.   


    $len = 4;
    $arr = array();
    for($i=1;$i<=$len;$i++){
        $arr[$i] = join('',range(1,$i));
            for($j = $i-1;$j>=1;$j--){
                $arr[$i] .= $j;
            }
    }
    $array = $arr;
    unset($arr[$len]);
    rsort($arr);
    $array = array_merge($array,$arr);
    print_r($array);
      

  16.   

    <?php 
      $num=9;
      for($i=1;$i<$num*2;$i++){
        $temm=$num-abs($num-$i);
        for($j=1;$j<2*$temm;$j++)   printf($temm-abs($temm-$j));
        printf("<br />");
      }
    ?>1
    121
    12321
    1234321
    123454321
    12345654321
    1234567654321
    123456787654321
    12345678987654321
    123456787654321
    1234567654321
    12345654321
    123454321
    1234321
    12321
    121
    1