PHP:访问数组变量
有人能帮我访问这个数组吗?我的索引有问题PHP:访问数组变量,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,有人能帮我访问这个数组吗?我的索引有问题 array(10) { [0]=>array(2) { ["t"]=>array(1) { ["tag"]=>string(3) "php" } [0]=>array(1) { ["NumOccurrances"]=>string(1) "2" } } [1]=>array(2) {
array(10) {
[0]=>array(2) {
["t"]=>array(1) {
["tag"]=>string(3) "php"
}
[0]=>array(1) {
["NumOccurrances"]=>string(1) "2"
}
}
[1]=>array(2) {
["t"]=>array(1) {
["tag"]=>string(6) "Tomcat"
}
[0]=>array(1) {
["NumOccurrances"]=>string(1) "1"
}
}
}
我想在foreach循环中使用它,比如“PHPX2”,但我在索引方面遇到了问题
谢谢
琼斯
foreach($array as $entity)
{
echo $entity['t']['tag'] . ' x ' . $entity[0]['NumOccurrances'];
}
会有用的。类似
foreach($array as $entity)
{
echo $entity['t']['tag'] . ' x ' . $entity[0]['NumOccurrances'];
}
会有用的。这样行吗
foreach ($tags as $t) {
echo $t['t']['tag'].' x '.$t[0]['NumOccurrances'].'<br />';
}
foreach($t标记){
回显$t['t']['tag'].'x'.$t[0]['numoccurrences'.].
;
}
结构似乎有点奇怪。如果这样做没有帮助,请提供阵列的其余部分。这样做可以吗
foreach ($tags as $t) {
echo $t['t']['tag'].' x '.$t[0]['NumOccurrances'].'<br />';
}
foreach( $a as $item ) {
echo $item['t']['tag'] . 'x' . $item[0]['NumOccurrances'] . '<br>';
}
foreach($t标记){
回显$t['t']['tag'].'x'.$t[0]['numoccurrences'.].
;
}
结构似乎有点奇怪。如果这没有帮助,请提供数组的其余部分。foreach($a作为$item){
foreach( $a as $item ) {
echo $item['t']['tag'] . 'x' . $item[0]['NumOccurrances'] . '<br>';
}
回显$item['t']['tag'].'x'.$item[0]['numoccurrences'.]。
;
}
foreach($a作为$item){
回显$item['t']['tag'].'x'.$item[0]['numoccurrences'.]。
;
}
我不会在这里使用foreach
循环foreach
创建数组的副本,因此不如for
循环有效。由于您的第一个维度是数字索引的,因此我将执行以下操作:
$count = count($array);
for ($i = 0; $i < $count; ++$i){
echo $array[$i]['t']['tag'] . " x " . $array[$i][0]['NumOccurrances'];
}
$count=count($array);
对于($i=0;$i<$count;++$i){
echo$array[$i]['t']['tag'].“x”。$array[$i][0]['numoccurrences'];
}
我同意vassilis的说法,数组结构很奇怪。我不会在这里使用
foreach
循环foreach
创建数组的副本,因此不如for
循环有效。由于您的第一个维度是数字索引的,因此我将执行以下操作:
$count = count($array);
for ($i = 0; $i < $count; ++$i){
echo $array[$i]['t']['tag'] . " x " . $array[$i][0]['NumOccurrances'];
}
$count=count($array);
对于($i=0;$i<$count;++$i){
echo$array[$i]['t']['tag'].“x”。$array[$i][0]['numoccurrences'];
}
我同意vassilis的说法,数组结构很奇怪。谢谢!是的,你是对的,这是一个奇怪的结构,但它来自一个cakePHP方法,看起来是这样的:$this->set('tags',$this->Project->query('SELECT t.tag,COUNT(*)AS numoccurrences FROM projects_tags,pt internal JOIN tags t ON t.id=pt.tag\u id GROUP BY t.tag ORDER BY 2 DESC');谢谢是的,你是对的,这是一个奇怪的结构,但它来自一个cakePHP方法,看起来是这样的:$this->set('tags',$this->Project->query('SELECT t.tag,COUNT(*)AS numoccurrences FROM projects_tags,pt internal JOIN tags t ON t.id=pt.tag\u id GROUP BY t.tag ORDER BY 2 DESC')-这是PHP吗?应该是
foreach($array as$value){…}
-1这是PHP吗?应该是foreach($array as$value){…}
。