0

I have this $photo array that I receive from a form post:

Array (
    [274] => Array (
        [10x10] => 0
        [10x15] => 3
        [13x13] => 2
        [13x18] => 0
        [15x15] => 0
        ...
    )
    [273] => Array (
        [10x10] => 1
        [10x15] => 0
        [13x13] => 0
        [13x18] => 0
        [15x15] => 0
        [20x20] => 0
        [20x28] => 2
        [30x30] => 0
        [30x40] => 0
        ...
    )
)

I can echo this array, except the fields with value 0.

<?php
echo "<table>";

foreach($foto as $key=>$value){

    foreach($value as $k => $v){

        if ($v != "0") {
            echo'<tr>';
            echo '<td>'  . $k . '</td>';
            echo '<td>'  . $v . '</td>';
            echo '</tr>';
        }
    }
}
echo "</table>";
?>

Which will result in:

10x15   3
13x13   2
10x10   1
20x28   2

But I also need the id of the array, in this case 274. I'm staring at this code for hours, been browsing the internet but I can't see it. How do i extract the id of the array (274).

Help/tips appreciated.

1
  • 5
    You already have it stored in $key Commented Nov 11, 2015 at 10:18

1 Answer 1

2

Try this:

<?php
echo '<table>';

foreach ($foto as $key => $value){
    foreach ($value as $k => $v){
        if ($v != "0") {
            echo '<tr>';
            echo '<td>' . $key . '</td>';
            echo '<td>' . $k . '</td>';
            echo '<td>' . $v . '</td>';
            echo '</tr>';
        }
    }
}

echo '</table>';
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Please never post "try this" (code-only) answers on Stackk Overflow -- be more generous to researchers.

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.