简体   繁体   English

多维PHP数组到HTML表的数组问题

[英]multidimensional PHP array of arrays to HTML table question

I've seen similar questions, but my issue is that My array is more complex than the ones i've seen and I'm not skilled enough as yet to extrapolate. 我已经看到了类似的问题,但是我的问题是我的数组比我所看到的要复杂得多,我还没有足够的技巧来推断。 I have an array as a constant, and I need to echo it into a table. 我有一个数组作为常量,我需要将其回显到表中。

Here is what I came up with. 这是我想出的。

echo "<table>";
foreach (TAX_RATES as $val => $key) {
    foreach($key as $kk =>$vv){
        foreach($vv as $aa => $bb){
            echo '<tr><td>'."$bb</br>".'</td>';
        }
        echo '<td>'."$kk</br>".'</td>';
    }
echo '<td>'."$val</br>".'</td></tr>';
}
echo "</table>";

Here is my array: 这是我的数组:

define('TAX_RATES',  
    array(
        'Single' => array(
            'Rates' => array(10,15,28,33,35,39.6),
            'Ranges' => array(0,8275,37650,91150,190150,413350,415050),
            'MinTax' => array(0,927.50,5183.75,18558.75,46278.75,119934.75,120529.75)
        ),
        'Married_Jointly' => array(
            'Rates' => array(10,15,25,28,33,35,39.6),
            'Ranges' => array(0,18550,75300,151900,231450,413350,466950),
            'MinTax' => array(0,1855,10367.5,29517.5,51791.5,111818.5,130578.5)
        ),
        'Married_Separately' => array(
            'Rates' => array(10,15,25,28,33,35,39.6),
            'Ranges' => array(0,9275,37650,75950,115728,206675,233475),
            'MinTax' => array(0,927.5,5183.75,14758.75,25895.75,55909.25,65289.25)
        ),
        'Head_Household' => array(
            'Rates' => array(10,15,25,28,33,35,39.6),
            'Ranges' => array(0,13250,50400,130150,210800,413350,441000),
            'MinTax' => array(0,1325,6897.5,26835,49417,116258.5,125936)
        )
    )
    );

The minTax value is just needed to calculate the actual tax. 仅需要minTax值即可计算实际税额。 The desired outcome is 理想的结果是

Single
Income Range          Tax
0                      0
8275                "927.50 + .1*income" (i can figure this part out)
37650               "5183.75 + .15*income"
etc                 etc

You can figure out from the below byu changing tr td 您可以通过更改tr td从下面找出

foreach($data as $k => $v)
{
  echo "<tr><td>$k</td></tr>";
    foreach($v as $key => $value)
    {
      echo "<tr><td>".$key."</td></tr>";
      echo "<tr>";
      for($i=0;$i<count($value);$i++) {
        echo "<td>".$value[$i]."</td>"; 
      }
      echo "</tr>";
    }
}

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM