0

I've following array:

Array
(
    [0] => Array
        (
            [0] => 585
            [1] => 596
        )

)

Now I want to print all values (585 & 595 .....) row for row in a loop. I need this an a loop because I need to to something with every value before the output. The problem is that I don't get all values, just one:

foreach ( $entries as $entry ) {
    echo $entry[ 0 ];
}

What am I doing wrong?

closed as off-topic by Jacob Peattie, Dave Romsey, Rick Hellewell, rudtek, Pat J Nov 3 '18 at 21:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1

If all your entries are nested, then you need to run another loop inside your first loop, but I'd test it to see if it's an array and that it's not empty.

foreach ( $entries as $entry ) {
    if ( is_array( $entry ) && !empty( $entry ) ) {
        foreach ( $entry as $sub_entry ) {
           echo $sub_entry;
        }
    }
}

I know there are other ways of being more complete about this, but this is the simplest answer I can think of off the top of my head.

  • 1
    You missed the ) at the end of the if :) and thanks a lot! Works great :D – Johnny97 Oct 15 '18 at 19:33
  • 1
    Haha, I usually miss something in my code :) I fixed it. – socki03 Oct 15 '18 at 19:34
  • 1
    If you'd be so kind as to mark it as correct, I'd appreciate it. Otherwise, if you're waiting for other answers, I understand. – socki03 Oct 15 '18 at 19:36
  • 1
    I've tried but I need to wait some minutes :) Be patient ;) – Johnny97 Oct 15 '18 at 19:37
  • 1
    "You can accept an answer in 47 seconds" – Johnny97 Oct 15 '18 at 19:37

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