Handige Harrie
Handige Harrie

Reputation: 149

PHP - Put mutlidimensional array values from same array in different divs

I'm trying to create a user order history list that shows up in a different div per reference number.

I'm using this multidimensional array like this:

$array = Array(
                "581095389012"=>Array(21,21,21),
                "112341234123"=>Array(25,25,25)
            );

Now here's the example of how I want it to be shown:

Div 1:

Reference number: 581095389012
Product id: getproductname(21)
Product id: getproductname(21)
Product id: getproductname(21)

div 2 begins here

Reference number: 112341234123
Product id: getproductname(21)
product id: getproductname(21)
product id: getproductname(21)

I've been stuck on this problem for a few hours now and I could really use some help to make this work.

I've tried to mess around with this code to get the values separated per reference number but I just couldn't solve how to do it:

function convertMultiArrayValuesToHistoryInformation($array){
    foreach($array as $key=>$value){
        //print_r($value.'<br/><br/>');
        foreach($value as $k=>$v){
            //return($v.'<br/>');
            print_r($v.',');
        }
    }
}

Any help would be appreciated. Thanks in advance.

Upvotes: 0

Views: 186

Answers (2)

Terrence S
Terrence S

Reputation: 13

foreach($array as $key => $value) {
    echo "<div>";
    echo "Reference number: ". $key;
    foreach ($value as $k => $v) {
        echo "Product id: ".getproductname($v);
    }
    echo "</div>";
}

Upvotes: 0

Surace
Surace

Reputation: 711

function convertMultiArrayValuesToHistoryInformation($array){
foreach($array as $key=>$value){
    echo '<div>Reference number: '.$key;
    foreach($value as $k=>$v){
            echo '<br><span>Product id: getproductname('.$v.')</span>';
    }
    echo '</div>';
}

}

Upvotes: 1

Related Questions