Illegal offset type error when => value is omitted

Posted by thomas on Stack Overflow See other posts from Stack Overflow or by thomas
Published on 2012-06-27T21:05:53Z Indexed on 2012/06/27 21:16 UTC
Read the original article Hit count: 218

Filed under:

Line 3 of the code below fails if I omit the => $v portion. I get the following error:

Warning: Illegal offset type in /home/site/page.php on line 404

When the [$k] in line 5 is changed to ['$k'], i receive the following error.

Notice: Undefined index: $k in /home/site/page.php on line 404

When it is like below with the the full $k => $v everything works though. I don't even use $v. Why do I need it in the foreach loop to make it work then?

<? if ( $arr[ 'status'][ 'chain'] ) { 
     foreach ( $arr[ 'status'][ 'chain'] as $k => $v) { ?>
        <tr>
            <td class="line_item_data status_td">
                <?= $ arr[ 'status'][ 'chain'][$k][ 'message'] ?>
            </td>
            <td align="center">
                <img src="images/green_check.gif" width="20" />
            </td>
        </tr>
    <? } 
} ?>

I did see this answer, but don't know that it really applies. Thanks so much!

© Stack Overflow or respective owner

Related posts about php