I have done it a thousand times before but for some reason I cant access array entries using their index/key. The only thing I am doing different is reading the json from a file and then using json_decode to populate this particular array of objects. When I use a foreach loop, I get the $post and the $key, but when I use the key to access the same value in the original array using $posts[$key], it returns nothing. I need to unset some specific entries and passing via reference hasnt helped either. Below is the code:
$contents = fread($fh, filesize($filepath));
fclose( $fh );
$posts = (array)json_decode($contents);
foreach( $posts as $key => &$post ){
$post_time = strtotime($post->post_date);
$now = strtotime('now');
if( ($now - $post_time) > 86400 ){
unset($posts[$key]);
}
}
print_r($posts)return?print_r($posts)and tryjson_decode($contents, true).