PHP:如何使用数组索引访问数组元素值 [英] PHP: How to access array element values using array-index
本文介绍了PHP:如何使用数组索引访问数组元素值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用array-index访问数组元素的值?
How to access array element values using array-index?
<?
$json = '{
"dynamic":{
"pageCount":"12",
"tableCount":"1"
}
}';
$arr = json_decode($json, true);
echo $arr['dynamic']['pageCount']; // working
echo $arr[0]['pageCount']; // not working
?>
我不知道动态"中的内容,因此我想动态访问pageCount值吗?
I will not know what is there in 'dynamic', so i want to access pageCount values dynamically?
推荐答案
array_values 是您要寻找的功能
示例:
<?php
$json = '{
"dynamic":{
"pageCount":"12",
"tableCount":"1"
}
}';
$arr = json_decode($json, true);
echo $arr['dynamic']['pageCount']; // working
$arr = array_values($arr);
echo $arr[0]['pageCount']; // NOW working
?>
这篇关于PHP:如何使用数组索引访问数组元素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文