如何在三列中获得结果?

时间:2016-02-24 16:19:30

标签: php multidimensional-array

这是我的代码......

<?php

    $arr1 = array(); 
    $arr2 = array();
    $arr3 = array();

     $intial_amount = 1000;
     $sum = 0;


        for($j = 3; $j<=24; $j = $j + 3)
        {
                if($j == 3)
                 {

                    $arr1[$j] = "";
                    $sum = $sum + 1000*3;
                 }
                else
                {
                $sum = $sum + 1000*3;
                $sum = $sum + ($sum * 0.02);
                 $arr1[$j] = $sum;
                }

        }
        for($j = 27; $j<=48; $j = $j + 3)
        {

                $sum = $sum + 1000*3;
                $sum = $sum + ($sum * 0.02);
                 $arr2[$j] = $sum;



        }
        for($j = 51; $j<=72; $j = $j + 3)
        {

                $sum = $sum + 1000*3;
                $sum = $sum + ($sum * 0.02);
                 $arr3[$j] = $sum;



        }
        $arr = array($arr1,$arr2,$arr3);
        foreach($arr as $key => $val)
        {
            foreach($val as $k => $v)
                {
                    echo $k."&nbsp;".$v."<br>";
                }

            echo "<br>";

        } 
?>

我希望结果分为三列..

2 个答案:

答案 0 :(得分:0)

我没有很好地关注您的代码,因为它不清楚您正在做什么,但如果您想在三列中显示列表,请使用CSS&#39; s {{ 1}}:

columns

答案 1 :(得分:0)

我想你想要那样的东西 enter image description here

如果您使用以下代码:

$arr1 = array(); 
$arr2 = array();
$arr3 = array();

 $intial_amount = 1000;
 $sum = 0;


    for($j = 3; $j<=24; $j = $j + 3)
    {
            if($j == 3)
             {

                $arr1[$j] = "";
                $sum = $sum + 1000*3;
             }
            else
            {
            $sum = $sum + 1000*3;
            $sum = $sum + ($sum * 0.02);
             $arr1[$j] = $sum;
            }

    }
    for($j = 27; $j<=48; $j = $j + 3)
    {

            $sum = $sum + 1000*3;
            $sum = $sum + ($sum * 0.02);
             $arr2[$j] = $sum;



    }
    for($j = 51; $j<=72; $j = $j + 3)
    {

            $sum = $sum + 1000*3;
            $sum = $sum + ($sum * 0.02);
             $arr3[$j] = $sum;



    }
    $arr = array($arr1,$arr2,$arr3);
    foreach($arr as $key => $val)
    {
        echo '<div style=" width:33%; float:left">';
        foreach($val as $k => $v)
            {

                echo $k."&nbsp;".$v."<br>";

            }
        echo '</div>';

    }