如何将数组输出到具有2列的行中

时间:2018-01-26 11:26:02

标签: php

以下是我的代码

...
remote:        warning "babel-loader@7.1.2" has incorrect peer dependency "babel-core@6 || 7 || ^7.0.0-alpha || ^7.0.0-beta || ^7.0.0-rc".
remote:        warning "babel-loader@7.1.2" has incorrect peer dependency "webpack@2 || 3".
remote:        warning "compression-webpack-plugin@1.1.3" has incorrect peer dependency "webpack@^2.0.0 || ^3.0.0".
remote:        warning "extract-text-webpack-plugin@3.0.2" has incorrect peer dependency "webpack@^3.1.0".
remote:        warning "file-loader@1.1.6" has incorrect peer dependency "webpack@^2.0.0 || ^3.0.0".
remote:        warning "postcss-cssnext@3.1.0" has incorrect peer dependency "caniuse-lite@^1.0.30000697".
remote:        warning "sass-loader@6.0.6" has incorrect peer dependency "node-sass@^4.0.0".
remote:        warning "sass-loader@6.0.6" has incorrect peer dependency "webpack@^2.0.0 || >= 3.0.0-rc.0 || ^3.0.0".
remote:        warning "uglifyjs-webpack-plugin@1.1.6" has incorrect peer dependency "webpack@^2.0.0 || ^3.0.0".
remote:        warning "webpack-manifest-plugin@1.3.2" has incorrect peer dependency "webpack@1 || 2 || 3".
remote:        warning "schema-utils@0.4.3" has incorrect peer dependency "webpack@^2.0.0 || ^3.0.0".
remote:        warning "ajv-keywords@2.1.1" has incorrect peer dependency "ajv@^5.0.0".
remote:        warning "uglifyjs-webpack-plugin@0.4.6" has incorrect peer dependency "webpack@^1.9 || ^2 || ^2.1.0-beta || ^2.2.0-rc || ^3.0.0".
remote:        warning "webpack-dev-server@2.11.1" has incorrect peer dependency "webpack@^2.2.0 || ^3.0.0".
remote:        warning "webpack-dev-middleware@1.12.2" has incorrect peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
remote:        [4/4] Building fresh packages...
remote:        Done in 29.88s.
...
remote: Verifying deploy... done.
To https://git.heroku.com/lecoqtrotteur.git
   42bda5b..2a24317  master -> master

以上数组值是项目规范的标题和值的组合,分隔为:

 $itemSpec = Array
(
    [0] => Brand:Adidas
    [1] => Style:Snowsuits & Bibs
    [2] => Country:China
    [3] => Material:Cotton Blend
    [4] => Sport:Bowling 
    [5] => Sleeve length:Short Sleeve
    [6] => Theme:Liverpool
)

下面是我想要实现的图像

我想要达到什么目标 enter image description here

以下是我当前的结果 enter image description here

enter image description here

我想在tr中只有4个td,如果我从代码中删除2个td,我得到的只是tr中的2 td,这不是我想要的结果,我希望有人可以帮助这个和提前谢谢。

1 个答案:

答案 0 :(得分:1)

<style type="text/css">

    .container { width: 1000px; float: left; }
    .container .item { width: 50%; float: left; height: 50px; }

</style>

<?php


$itemSpec = Array
(
    0 => "Brand:Adidas",
    1 => "Style:Snowsuits & Bibs",
    2 => "Country:China",
    3 => "Material:Cotton Blend",
    4 => "Sport:Bowling", 
    5 => "Sleeve length:Short Sleeve",
    6 => "Theme:Liverpool"
);



echo '<div class="container">';

foreach ( $itemSpec as $v ) {

    $allItemSpec = explode(':', $v);

    if( $allItemSpec[0] == "Country" ) {

        $allItemSpec[0] = "Country/Region of Manufacture";

    }


     echo '<div class="item">' .$allItemSpec[0]. ":" .$allItemSpec[1] . '</div>';

}

echo '</div>';

?>