0

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.

2 Answers 2

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

}

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

Comments

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

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.