提取php数组值

时间:2014-11-27 21:44:49

标签: php arrays extract

我有以下数组(使用var_dump公开)。

array (size=3)
    'auth' => string 'debug' (length=5)
    'url' => string 'http://X.X.X.X/status.cgi?' (length=31)
    'page' => string '{ "host": {   "uptime": 1543,     "time": "2011-07-26 12:07:40",  "fwversion": "v1.1.1",  "hostname": "ASDASDASD",    "netrole": "DFDFDF"  },  "lan": {   "status": [{ "plugged": 1, "speed": 100, "duplex": 1 }],    "hwaddr": "00:00:22:11:11:11",  "ip": "",   "rx": { "bytes": 5988, "packets": 83, "errors": 0 },    "tx": { "bytes": 9496, "packets": 120, "errors": 0 }  },  "wan": {  "status": [],   "hwaddr": "00:00:00:00:00:00",  "ip": "",   "rx": { "bytes": 0, "packets": 0, "errors": 0 },    "tx": { "bytes": 0, "packets"'... (length=1779)

我需要从广域网中提取信息,如ip或rx ......

我尝试过使用$ array ['页面'] [' wan'] [' rx']但是什么都没有!!!

感谢。

1 个答案:

答案 0 :(得分:3)

page的{​​{1}}值实际上不是数组,而是字符串。由于它是一个JSON字符串,您应该使用json_decode将字符串解码为一个有意义的格式供PHP处理:

$array

以获得RX为例:

$page = json_decode($array['page']);
$pageArray = json_decode($array['page']); // Returned as an array