您好我有快速提问。 我有一个阵列女巫看起来像那样:
Array ( [id] => 311 [file] => [name] => Mobilny [minutes] => [connection_type] => [price] => [price_landline] => [price_mobile] => [prices] => [{"city_id":"304","months":"0","price":"1","minutes":"0"}] [link] => mobilny [page_id] => 3521 [hidden_number] => Y [position] => 0 [date] => 2016-07-26 [date_modify] => 2016-08-29 )
这个数组有这个专栏:
[prices] => [{"city_id":"304","months":"0","price":"1","minutes":"0"}]
我的问题是,这个值是否被视为字符串?
[{"city_id":"304","months":"0","price":"1","minutes":"0"}]
如何从city_id
访问价值?当我使用$table[0]['prices']
时,我会得到以下信息:[{"city_id":"304","months":"0","price":"1","minutes":"0"}]
而且我不知道如何从中获取city_id
。
答案 0 :(得分:1)
您有JSON格式的值。使用json_decode
函数对其进行解码。
//Decode JSON to object
$decoded = json_decode($table[0]['prices']);
$cityId = $decoded->city_id;
//Decode JSON to associative array
$decoded = json_decode($table[0]['prices'], true);
$cityId = $decoded['city_id'];