I have 50 items in an array that looks something like this:
array:50 [▼
0 => {#253 ▼
+"message": "message_1"
+"created_time": {#254 ▼
+"date": "2016-03-03 07:54:05.000000"
+"timezone_type": 1
+"timezone": "+00:00"
}
+"id": "167633226631991_1051771021551536"
}
1 => {#255 ▼
+"message": "message_2"
+"created_time": {#256 ▼
+"date": "2016-03-02 13:35:26.000000"
+"timezone_type": 1
+"timezone": "+00:00"
}
+"id": "167633226631991_1051313571597281"
}
]
I need to grab each variable within the array. But I keep getting an error that reads:
Undefined property: stdClass::$message
Im not sure what Im missing I've tried doing:
foreach ($posts as $post) {
$test = array('message' => $post->message );
}
and also
$a = -1;
$alpha = 0;
$omega = count($posts);
$empty_array = array();
foreach (range($alpha,$omega) as $i) {
++$a;
$test = $posts[$a]->message;
array_push($empty_array, $test);
}
but I'm getting the same error. Im using laravel 5.2.
Update: The array is coming from facebook's graph API. I am converting the json format using:
$posts = json_decode($userNode['posts']);
Doing this then displays the array:50 as above.
dd($post)show within the foreach?Cannot use object of type stdClass as arraydd($post)I get{#253 ▼ +"message": "message_1" +"created_time": {#254 ▼ +"date": "2016-03-03 07:54:05.000000" +"timezone_type": 1 +"timezone": "+00:00" } +"id": "167633226631991_1051771021551536" }