1
 Array
(
[0] => Array
        (
            [id] => 239

            [order_no] => 787351

        )

    [1] => Array
        (
            [id] => 239
           [order_no] => 787745

        )
)

This is my array now i want to print all its value. I have used this code and when there is 1 item in array it works but when there are 2 items in array it does not work.

 foreach ($Item as $OrderItem){
        Mage::log("test");
       $amount = item['order_no'];
   }
1

4 Answers 4

0

Check with below code

foreach ($Item as $OrderItem){
    Mage::log("test");
    $amount = $OrderItem['order_no'];
}
0
foreach ($Item as $OrderItem){
        Mage::log("test");
       $amount =  $OrderItem['order_no'];
   }
0

I think you are trying to print $amount after the foreach and then only the last value will be printed.

Try the following:

    $orderItems = array(
        array(
            'id' => 239,
            '787351' => 787351
        ),
        array (
            'id' => 240,
            'order_no' => 787745
        )
    );

    foreach ($orderItems as $orderItem) {
        Mage::log($orderItem['order_no']);
        echo $orderItem['order_no'] . "\n";
    }
0

You are doing only one mistake that using parent array instead of sub array please see the correction below

$Item = array(
        array(
            'id' => 239,
            'order_no' => 787351
        ),
        array (
            'id' => 240,
            'order_no' => 787745
        )
    );

    foreach ($Item as $OrderItem) {
        echo $OrderItem['order_no'] . "\n";
    }

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.