Home  >  Article  >  Backend Development  >  php中数组p[]表示什么?

php中数组p[]表示什么?

WBOY
WBOYOriginal
2016-06-23 13:59:321257browse

php中数组p[]表示什么?

$g = array();

foreach($re as $key => $val)
{
$g[] = new class_a($val) ;
}

p[]表示当前数组指针?


回复讨论(解决方案)

手册中有:
用方括号的语法新建/修改
可以通过明示地设定值来改变一个现有的数组。 

这是通过在方括号内指定键名来给数组赋值实现的。也可以省略键名,在这种情况下给变量名加上一对空的方括号(“[]”)。 $arr[key] = value;
$arr[] = value;
// key 可以是 integer 或者 string
// value 可以为任何值。
 

$g[] 是给数组$g赋值,在你的例子中索引从0开始。

$g[]就是一个空的数组。

感谢2位版主和zy205817 ,


可以省略键名,在这种情况下给变量名加上一对空的方括号(“[]”)。 $arr[key] = value;
 $arr[] = value;

mi明白了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn