MyBB Community Forums

Full Version: PHP Warning
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am completely stumped at why I am getting a PHP Warning in my code. I have tried all sorts to fix it, but still nothing. The code works standalone without MyBB in Codeigniter, I have just ported it across to MyBB.

Basically I have a multidimensional array along the lines of:
Array
(
    [status] => success
    [items] => Array
        (
            [0] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [name] => 'Test Item'
                        )
                )

            [1] => 1
        )
)

My for loop looks like this:
for($i_item = 0;$i_item < $return_array['items'][1];$i_item++)
{
}


I managed to get it outputting one item (baring in mind I have hidden a lot in the array above). However I get a warning with:

Quote:Warning [2] Illegal string offset 'items' - Line: 49 - File: C:\xampp\htdocs\mybb\steam.php PHP 5.4.16 (WINNT)

I have Googled the error and try putting in measures such as:

if(is_array($return_array['items']) and !empty($return_array['items'])

if(isset($return_array['items'][$i_item]))

But I still have the error. It's pretty confusing seeing as it works outside MyBB.

Any help is appreciated.[/code]
I think "$i_item" needs to be a constant, not a variable. So replace it with "i" or something like that.
Thanks. I had to change it to this below. Still confused as to why I had to change it, but alas it works.

        $items = $user_backpack_items['items'][0];
        $count = $user_backpack_items['items'][1];

        // Start looping through our items array.
        for($i_item = 0;$i_item < $count;$i_item++) { ... }