是否有一个PHP相当于"新的Array(数字)QUOT;在JavaScript? [英] Is there a PHP equivalent of "new Array (number)" in javascript?
问题描述
我是想基本的JavaScript函数转换成PHP和我看到的一个变量被宣布 VAR变量=新阵列(13)
。
我知道PHP变量声明如下: $变量=阵列()
但如何在在13的新阵列(13)
?这是否转化为 $变量=阵列(13)
?我已经试过了,但它似乎没有工作。
这在Javascript中
VAR的结果=新的Array(13);
这成为在PHP中,我是不是正确的?
$结果=阵列(13);
其实,在这种情况下,你要创建的数组大小 13
。
您并不真的需要在PHP preallocate数组,但你可以这样做:
$结果= array_fill(0,12,NULL);
这将创建一个具有13个元素(索引0至12),其值空
。
I was trying to convert basic Javascript function into PHP, and I saw that one of the variables was declared var Variable = new Array (13)
.
I know that PHP variables are declared like: $variable = array()
but what about the "13" in new Array(13)
? does that translate to $variable = array(13)
? I've tried that but it didn't seem to work.
This in Javascript
var results = new Array (13);
becomes this in PHP, am I correct?
$results = array(13);
Actually, in this context, you're creating an array of size 13
.
You don't really need to preallocate arrays in PHP, but you can do something like:
$result = array_fill( 0, 12, null);
This will create an array with 13 elements (indexes 0 through 12) whose values are null
.
这篇关于是否有一个PHP相当于"新的Array(数字)QUOT;在JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!