Created
December 25, 2017 10:10
-
-
Save yeungon/90477d815587a1b69e46a27b34fd0a1a to your computer and use it in GitHub Desktop.
Remove $key in json using PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = file_get_contents('http://localhost/search/oxfordupdate.json'); | |
$data = json_decode($file, TRUE); | |
// unset($file);//prevent memory leaks for large json. | |
//insert data here | |
foreach($data['RECORDS'] as $key=>$value) { | |
foreach ($value as $key2 => $value2) { | |
$data2[] = $value2; | |
// print_r($data2); | |
// echo $key2; | |
// // unset($key2); | |
} | |
// echo "<pre>"; | |
// // print_r($data['RECORDS']); | |
// print_r($key); | |
// echo "</pre>"; | |
} | |
//save the file | |
file_put_contents('oxfordwordonly.json',json_encode($data2)); | |
unset($data);//release memory | |
/* | |
<?php | |
$animals = '{ | |
"0":{"kind":"mammal","name":"Pussy the Cat","weight":"12kg","age":"5"}, | |
"1":{"kind":"mammal","name":"Roxy the Dog","weight":"25kg","age":"8"}, | |
"2":{"kind":"fish","name":"Piranha the Fish","weight":"1kg","age":"1"}, | |
"3":{"kind":"bird","name":"Einstein the Parrot","weight":"0.5kg","age":"4"} | |
}'; | |
$animals = json_decode($animals, true); | |
foreach ($animals as $key => $value) { | |
if (in_array('Piranha the Fish', $value)) { | |
unset($animals[$key]); | |
} | |
} | |
$animals = json_encode($animals); | |
?>*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment