0

This is what I have achieved so far.

$product1 = array("Watch"=>"100$", "Shoes"=>"550$", "Jacket"=>"430$" , "Sweater"=>"230$" );
$product2 = array("Watch"=>"200$", "Shoes"=>"450$", "Jacket"=>"430$" , "Sweater"=>"230$" );
$product3 = array("Watch"=>"300$", "Shoes"=>"350$", "Jacket"=>"430$" , "Sweater"=>"230$" );
$product4 = array("Watch"=>"400$", "Shoes"=>"250$", "Jacket"=>"430$" , "Sweater"=>"230$" );

foreach($product1 as $x => $x_value) {
    echo "Name=" . $x ."<br>". ", Price=" . $x_value."<br>";
}

foreach($product2 as $x => $x_value) {
    echo "Name=" . $x ."<br>". ", Price=" . $x_value."<br>";
}

I want the product1 output in 1st row and in first four columns. Similary product2 output in 2nd row and in four columns.

Desired result: expected output

1
  • Please start reading a few "getting started" tutorials about HTML page layout. There is little sense in us repeating all that here if you can simply read it elsewhere on the internet. Commented Dec 13, 2016 at 16:45

1 Answer 1

1

What about something like that:

echo '<table>';
echo '<tr>';


foreach ($product1 as $x => $x_value) {
    echo '<td>';
    echo "Name=" . $x ."<br>". "Price=" . $x_value;
    echo '</td>';
}


echo '</tr>';
echo '<tr>';


foreach ($product2 as $x => $x_value) {
    echo '<td>';
    echo "Name=" . $x ."<br>". "Price=" . $x_value;
    echo '</td>';
}


echo '</tr>';
echo '<tr>';


foreach ($product3 as $x => $x_value) {
    echo '<td>';
    echo "Name=" . $x ."<br>". "Price=" . $x_value;
    echo '</td>';
}


echo '</tr>';
echo '<tr>';


foreach ($product4 as $x => $x_value) {
    echo '<td>';
    echo "Name=" . $x ."<br>". "Price=" . $x_value;
    echo '</td>';
}


echo '</tr>';
echo '</table>';

Demo

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

Comments

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.