1

I am try to loop through the following stdClass Object array.

Array
(
[0] => stdClass Object
    (
        [key] => 49
        [values] => Array
            (
                [0] => Kansas City Chiefs
                [1] => -3
                [2] => Denver Broncos
                [3] => 3
                [4] => 41
                [5] => 2015-09-18 00:25:00
            )

    )

[1] => stdClass Object
    (
        [key] => 50
        [values] => Array
            (
                [0] => Carolina Panthers
                [1] => -3.5
                [2] => Houston Texans
                [3] => 3.5
                [4] => 40
                [5] => 2015-09-20 17:00:00
            )

    )

[2] => stdClass Object
    (
        [key] => 51
        [values] => Array
            (
                [0] => New Orleans Saints
                [1] => -10
                [2] => Tampa Bay Buccaneers
                [3] => 10
                [4] => 47
                [5] => 2015-09-20 17:00:00
            )

    )

[3] => stdClass Object
    (
        [key] => 52
        [values] => Array
            (
                [0] => Pittsburgh Steelers
                [1] => -6
                [2] => San Francisco 49ers
                [3] => 6
                [4] => 45
                [5] => 2015-09-20 17:00:00
            )

    )

[4] => stdClass Object
    (
        [key] => 53
        [values] => Array
            (
                [0] => Minnesota Vikings
                [1] => -3
                [2] => Detroit Lions
                [3] => 3
                [4] => 43
                [5] => 2015-09-20 17:00:00
            )

    )

[5] => stdClass Object
    (
        [key] => 54
        [values] => Array
            (
                [0] => Buffalo Bills
                [1] => 1
                [2] => New England Patriots
                [3] => -1
                [4] => 45
                [5] => 2015-09-20 17:00:00
            )

    )

[6] => stdClass Object
    (
        [key] => 55
        [values] => Array
            (
                [0] => Chicago Bears
                [1] => 2
                [2] => Arizona Cardinals
                [3] => -2
                [4] => 45
                [5] => 2015-09-20 17:00:00
            )

    )

[7] => stdClass Object
    (
        [key] => 56
        [values] => Array
            (
                [0] => Cleveland Browns
                [1] => 1
                [2] => Tennessee Titans
                [3] => -1
                [4] => 41
                [5] => 2015-09-20 17:00:00
            )

    )

[8] => stdClass Object
    (
        [key] => 57
        [values] => Array
            (
                [0] => Cincinnati Bengals
                [1] => -3.5
                [2] => San Diego Chargers
                [3] => 3.5
                [4] => 46
                [5] => 2015-09-20 17:00:00
            )

    )

[9] => stdClass Object
    (
        [key] => 58
        [values] => Array
            (
                [0] => Washington Redskins
                [1] => 3.5
                [2] => St. Louis Rams
                [3] => -3.5
                [4] => 41
                [5] => 2015-09-20 17:00:00
            )

    )

[10] => stdClass Object
    (
        [key] => 59
        [values] => Array
            (
                [0] => New York Giants
                [1] => -2.5
                [2] => Atlanta Falcons
                [3] => 2.5
                [4] => 51
                [5] => 2015-09-20 17:00:00
            )

    )

[11] => stdClass Object
    (
        [key] => 60
        [values] => Array
            (
                [0] => Oakland Raiders
                [1] => 6
                [2] => Baltimore Ravens
                [3] => -6
                [4] => 43
                [5] => 2015-09-20 20:05:00
            )

    )

[12] => stdClass Object
    (
        [key] => 61
        [values] => Array
            (
                [0] => Jacksonville Jaguars
                [1] => 6
                [2] => Miami Dolphins
                [3] => -6
                [4] => 41
                [5] => 2015-09-20 20:05:00
            )

    )

[13] => stdClass Object
    (
        [key] => 62
        [values] => Array
            (
                [0] => Philadelphia Eagles
                [1] => -5
                [2] => Dallas Cowboys
                [3] => 5
                [4] => 55
                [5] => 2015-09-20 20:25:00
            )

    )

[14] => stdClass Object
    (
        [key] => 63
        [values] => Array
            (
                [0] => Green Bay Packers
                [1] => -3.5
                [2] => Seattle Seahawks
                [3] => 3.5
                [4] => 49
                [5] => 2015-09-21 00:30:00
            )

    )

[15] => stdClass Object
    (
        [key] => 64
        [values] => Array
            (
                [0] => Indianapolis Colts
                [1] => -7
                [2] => New York Jets
                [3] => 7
                [4] => 47
                [5] => 2015-09-22 00:30:00
            )

    )

)

When I use the following syntax it prints one line correctly and one line blank

foreach($tableData as $obj)
{
foreach ($obj as $tr)
{

    echo '<tr><td>'.$mysqldate = date( 'g:ia - D', $phpdate =     strtotime($tr[5])- 60 * 60 * 5).'</td><td><strong>'.($i += 4).'</strong> '.$tr[0].'<br><br><strong>'.($iii += 4).'</strong> Over</td><td>'.$tr[1].'<br><br>'.$tr[4].'</td><td><strong>'.($ii += 4).'</strong> '.$tr[2].'<br><br><strong>'.($iiii += 4).'</strong> Under</td><td>'.$tr[3].'<br><br>'.$tr[4].'</td></tr>';
}
}

My guess is that its looping through the key, when is where it comes up blank, than it goes through the values where i get the results I want. I've tried a few things that does seem to work. How do I loop through avoiding the [key]?

3
  • Are you sure you really have an array with objects? =&gt; Seems a bit weird Commented Sep 20, 2015 at 21:07
  • it has those cause i copied it from source Commented Sep 20, 2015 at 21:09
  • A similar question was asked a few years ago: [enter link description here][1] [1]: stackoverflow.com/questions/16287782/… Commented Sep 20, 2015 at 21:18

2 Answers 2

2

You need to access the object's values property instead, like this:

foreach($tableData as $obj)
{
  $tr = $obj->values;
  echo ....
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

foreach($tableData as $key => $val){
  $val2 = $val->values;
   echo $val[0];
}

2 Comments

Why? He wants to access the array of arrays inside the array of objects.
The objects don't have arrays of arrays. See my previously-posted answer.

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.