如何在PHP对象数组中获取值

时间:2018-06-07 13:03:39

标签: php arrays json

我有这个JSON

{
    "code": "1",
    "message": "User Created",
    "data": {
        "name": "Customer Name",
        "email": "customer@email.com"
    }
}

如何使用PHP获取姓名和电子邮件?

1 个答案:

答案 0 :(得分:2)

$json_str = '{
    "code": "1",
    "message": "User Created",
    "data": {
        "name": "Customer Name",
        "email": "customer@email.com"
    }
}';

$arr = json_decode($json_str, true);
echo $arr['data']['name'];
echo $arr['data']['email'];