php删除json条目,用php从json中删除元素

对不起我的英语.

我知道还有很多其他问题,但是我找不到任何可以帮助我的东西(或者我可能不理解).

我有一个这样的json(autocaricate.json):

[

{

"nome":"LABORGHINI GALLARDO",

"descrizione":"LAMBORGHINI GALLARDO ED. NERA- ANNO 2007- ",

"indirizzo_pubblicato":"autocaricateeea\/LABORGHINI GALLARDO31072013-023853\/LABORGHINI GALLARDO31072013-023853.json",

"indirizzo_immagine_copertina":"autocaricateeea\/LABORGHINI GALLARDO31072013-023853\/IMG_1414 (600x448).jpg",

"indirizzo_paginaauto":"autocaricateeea\/LABORGHINI GALLARDO31072013-023853\/index.html"

},

{

"nome":"RENAULT MEGANE",

"descrizione":"RENAULT MEGANE -ANNO 2006-DIESEL-CC. 1461",

"indirizzo_pubblicato":"autocaricateeea\/RENAULT MEGANE31072013-024103\/RENAULT MEGANE31072013-024103.json",

"indirizzo_immagine_copertina":"autocaricateeea\/RENAULT MEGANE31072013-024103\/P1080949 (600x450).jpg",

"indirizzo_paginaauto":"autocaricateeea\/RENAULT MEGANE31072013-024103\/index.html"

},

{

"nome":"FORD MONDEO",

"descrizione":"FORD MONDEO SINISTRATA- ANNO 2009- DIESEL- CC. 1997-",

"indirizzo_pubblicato":"autocaricateeea\/FORD MONDEO31072013-045216\/FORD MONDEO31072013-045216.json",

"indirizzo_immagine_copertina":"autocaricateeea\/FORD MONDEO31072013-045216\/P1080971 (600x450).jpg",

"indirizzo_paginaauto":"autocaricateeea\/FORD MONDEO31072013-045216\/index.html"

}

]

我想用json从json中删除一个元素(一辆汽车,例如RENAULT MEGANE).

我写了一个这样的函数:

$url = $GET['indirizzo']; //this variable get an address like autocaricateeea\/RENAULT MEGANE31072013-024103\/index.html

$file = file_get_contents('autocaricate.json');

$data = json_decode($file);

unset($file);//prevent memory leaks for large json.

//insert data here

foreach($data as $elemento) {

$valore = $elemento['indirizzo_paginaauto'];

if($valore == $url){

****** enter code here ******

}

}

//save the file

file_put_contents('autocaricate.json',json_encode($data));

unset($data);//release memory

我写的代码是从json文件中删除任何属性(对于我们想要移除的汽车,例如RENAULT MEGANE)?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值