0

Below is my code

 $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
)

The above array value is a combination of title and value of item specification separated by:

foreach ($itemSpec as $v){
     $allItemSpec = explode(':', $v);

     if($allItemSpec[0] == "Country"){
     $allItemSpec[0] = "Country/Region of 
       Manufacture";
       }
      $allItemSpec = "<tr>"
       "<td>$allItemSpec[0]:</td>
      <td>$allItemSpec[1]</td>
        </tr>";
       echo $allItemSpec;
      }

Below is the image of what i wanted to acheive

WHAT I WANTED TO ACHIEVE enter image description here

THE BELOW IS THE CURRENT RESULT I'M HAVING enter image description here

enter image description here

I want to have only 4 td in a tr, and if I remove 2 td from within the code what I get is only 2 td within a tr which is not the result I want, I hope someone can help with this and thanks in advance.

3
  • the current result is not what the code is doing. Also use ['key' => 'value'] instead of explode. Please send the actual current code Commented Jan 26, 2018 at 11:35
  • Thanks for your reply i will edit and explain in more details Commented Jan 26, 2018 at 11:43
  • @ Friedrich Roell i edited my question and i changed the second image which is the actual result i'm getting from the code above, array $itemspec as you can see above is an index array and the value is a string separated by : sign, now i want to get the string on the left of the : sign as the title and the string on the right as the value so i used explode, which gives me desire result, now i need to output the result in a table and i need to output only 2 on a tr so if i have 7 in the array it means i need 4 tr with one of it only having on td, but in my result i got 7 rows Commented Jan 26, 2018 at 12:08

1 Answer 1

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>';

?>
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your replay i got excatly the same result as yours so maybe what i needed is the css styling to put say for instance Brand: Adidas and Style: Snowsuits & Bibs on the same row, please can you help me with the css, thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.