0

I have two arrays at the bottom, I'm looking to output their values by a numeric index. Seems so simple yet I cannot get it to work for the life of me. I'm nesting these into a few other foreach loops.

 $x = $ppro_model->orderedByDate($val->ProdCode);
                          $xx = $ppro_model->receivedByDate($val->ProdCode);
                          $ordQty = arrayDateBuilder($x, 'ordQUANTITY', $daterange);
                          $recQty = arrayDateBuilder($xx, 'recQUANTITY', $daterange);

$ordQty and $recQty will ALWAYS have the same amount of elements. So ideally I would like to be able to do the following:

 for($i = 0; $i <= count($ordQty); $i++){
                        echo "<td>";
                        echo $ordQty['recQUANTITY'][$i];
                        echo $recQty['ordQUANTITY'][$i];
                        echo "<td>";
                    }

but I'm definitely doing something wrong. Any advice would be appreciated.

I also tried:

  echo $ordQty[$i];

to not avail.

array (size=7)
  0 => 
    array (size=2)
      'DATE' => string '20141110' (length=8)
      'ordQUANTITY' => string '55.00' (length=5)
  1 => 
    array (size=2)
      'DATE' => string '20141111' (length=8)
      'ordQUANTITY' => string '80.00' (length=5)
  2 => 
    array (size=2)
      'DATE' => string '20141112' (length=8)
      'ordQUANTITY' => string '70.00' (length=5)
  3 => 
    array (size=2)
      'DATE' => string '20141113' (length=8)
      'ordQUANTITY' => string '135.00' (length=6)
  4 => 
    array (size=2)
      'DATE' => string '20141114' (length=8)
      'ordQUANTITY' => string '70.00' (length=5)
  5 => 
    array (size=2)
      'DATE' => string '20141115' (length=8)
      'ordQUANTITY' => string '120.00' (length=6)
  6 => 
    array (size=2)
      'DATE' => string '20141116' (length=8)
      'ordQUANTITY' => string '0' (length=1)

then one like:

array (size=7)
  0 => 
    array (size=2)
      'DATE' => string '20141110' (length=8)
      'recQUANTITY' => string '0' (length=1)
  1 => 
    array (size=2)
      'DATE' => string '20141111' (length=8)
      'recQUANTITY' => string '0' (length=1)
  2 => 
    array (size=2)
      'DATE' => string '20141112' (length=8)
      'recQUANTITY' => string '0' (length=1)
  3 => 
    array (size=2)
      'DATE' => string '20141113' (length=8)
      'recQUANTITY' => string '0' (length=1)
  4 => 
    array (size=2)
      'DATE' => string '20141114' (length=8)
      'recQUANTITY' => string '0' (length=1)
  5 => 
    array (size=2)
      'DATE' => string '20141115' (length=8)
      'recQUANTITY' => string '0' (length=1)
  6 => 
    array (size=2)
      'DATE' => string '20141116' (length=8)
      'recQUANTITY' => string '0' (length=1)
3
  • 2
    echo $ordQty[$i]['recQUANTITY']; ? Commented Nov 12, 2014 at 21:04
  • @Hobbes: Post as an answer. Commented Nov 12, 2014 at 21:07
  • 1
    as per Barmar's answer, use foreach to make your life easy. Commented Nov 12, 2014 at 21:10

1 Answer 1

2

You had your array expressions backward, it should be $ordQty[$i]['ordQUANTITY']. Also, your loop condition was wrong, it should be $i < count($ordQty), not <=, since array indexes go from 0 to count-1.

It can be simplified a bit using foreach.

foreach ($ordQty as $i => $ordElt) {
    echo "<td>";
    echo $ordElt['ordQUANTITY'];
    echo $recQty[$i]['recQUANTITY'];
    echo "<td>";
}
Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much, simple stupid things get over looked sometimes.

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.