How to unset value from json encode array using php

  json, php

How can i delete value from json encode array using php. here is my json format.
{"1":["fileid",time],"2":["fileid",time],"3":["fileid",time]}. And here is my php code. but nothing is delete. i want to remove whole array value ex "3":["fileid",time] when function execute.

<?php
$filename = "test.json";
$fopen = fopen($filename,"r");
$fgets = fgets($fopen);
fclose($fopen);
$decode = json_decode($fgets,true);
foreach($decode as $post){
 $dif = time() - $post[1];
 if($dif > 5){
     unset($decode[1]);  
 }
?>

Thanks

Source: Ask PHP

LEAVE A COMMENT