fork download
  1. <?php
  2.  
  3. $arr = [
  4. [
  5. 'COLOR' => 'Red',
  6. 'WEIGHT' => 20
  7. ],
  8.  
  9. [
  10. 'COLOR' => 'Red',
  11. 'WEIGHT' => 25
  12. ],
  13.  
  14. [
  15. 'COLOR' => 'Red',
  16. 'WEIGHT' => 30
  17. ],
  18.  
  19. [
  20. 'COLOR' => 'Green',
  21. 'WEIGHT' => 20
  22. ],
  23.  
  24. [
  25. 'COLOR' => 'Green',
  26. 'WEIGHT' => 25
  27. ],
  28.  
  29. [
  30. 'COLOR' => 'Green',
  31. 'WEIGHT' => 30
  32. ]
  33. ];
  34.  
  35. $out = [];
  36.  
  37. foreach ($arr as $a) {
  38. $out[$a['COLOR']][] = $a['WEIGHT'];
  39. }
  40.  
  41. ?>
  42.  
  43. <table>
  44. <?php foreach ($out as $key => $arr) { ?>
  45. <tr>
  46. <th><?= $key ?></th>
  47. </tr>
  48. <?php foreach ($arr as $item) { ?>
  49. <tr>
  50. <td>
  51. <div>
  52. <input type="text" value="<?=$item?>">
  53. </div>
  54. </td>
  55. </tr>
  56. <?php } ?>
  57. <?php } ?>
  58. </table>
Success #stdin #stdout 0.02s 24332KB
stdin
Standard input is empty
stdout
<table>
            <tr>
            <th>Red</th>
        </tr>
                    <tr>
                <td>
                    <div>
                        <input type="text" value="20">
                    </div>
                </td>
            </tr>
                    <tr>
                <td>
                    <div>
                        <input type="text" value="25">
                    </div>
                </td>
            </tr>
                    <tr>
                <td>
                    <div>
                        <input type="text" value="30">
                    </div>
                </td>
            </tr>
                    <tr>
            <th>Green</th>
        </tr>
                    <tr>
                <td>
                    <div>
                        <input type="text" value="20">
                    </div>
                </td>
            </tr>
                    <tr>
                <td>
                    <div>
                        <input type="text" value="25">
                    </div>
                </td>
            </tr>
                    <tr>
                <td>
                    <div>
                        <input type="text" value="30">
                    </div>
                </td>
            </tr>
            </table>