如何在mysql和php中搜索json数组中的数据?

but5z9lq  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(209)
{"email": "afadf%40gmail.com", 
"phone": "2525", 
"rooms": "4", 
"floors": "2", 
"user_id": "2", 
"ad_title": "sdafasfdasf", 
"features": "['Elevator','Center Stairs']", 
"car_space": "5", 
"full_name": "adaf", 
"sortOrder": "10000", 
"build_year": "2018"
}

我想用上面的json格式搜索特性为“电梯”的数据。

nue99wik

nue99wik1#

你可以用 json_decode() 功能。此函数将从json返回一个数组。
前任:

$data = '{
    "email": "afadf%40gmail.com", 
    "phone": "2525", 
    "rooms": "4", 
    "floors": "2", 
    "user_id": "2", 
    "ad_title": "sdafasfdasf", 
    "features": "['Elevator','Center Stairs']", 
    "car_space": "5", 
    "full_name": "adaf", 
    "sortOrder": "10000", 
    "build_year": "2018"
}';
$arr = json_decode($data);
//The $arr variable will be an array contains the data from $data variable

然后,你可以使用 array_search() 要搜索的函数。一些参考资料:
堆栈溢出
W3学校

相关问题