Delete from json using php

前端 未结 6 766
不思量自难忘°
不思量自难忘° 2020-12-30 18:32

my Current json code :

{\"Results\":[{\"username\":\"test\",\"password\":\"test\"},{\"username\":\"test\",\"password\":\"test\"},{\"username\":\"google\",\"p         


        
6条回答
  •  醉梦人生
    2020-12-30 18:41

    $json = '
    {
      "Results":[
        {"username":"test","password":"test"},
        {"username":"test","password":"test"},
        {"username":"google","password":"test"},
        {"username":"yahoo","password":"test"},
        {"username":"hotmail","password":"test"}
      ]
    }';
    
    $arr = json_decode($json, true);
    array_filter($arr, function($v) {
      return !($v['username'] == 'google' && $v['password'] == 'test');
    });
    $json = json_encode($arr);
    

提交回复
热议问题