I have this PHP code -
<?php
for($i=1; $i<=1000; $i++) {
$array=array();
$array[$i]=54*$i;
$arr=array($array[$i].",");
foreach ($arr as $value) {
echo $value;
}
}
?>
I tried with:
var i;
for(i=1;i<=1000;i++) {
var array = new Array();
array[i] = 54*i;
var arr = new Array();
arr.push(array[i]+",");
}
alert(arr)
But it doesn't work. Where's the mistake?
Wild stab.. because the PHP code while it may produce the expected output, is actually 'wrong' (wrong on the basis that you may expect the array to hold all those values, and it doesn't).
so here's the php (fixed).
<?php
$a = array();
$stringVersion = '';
for($i=1; $i<=1000; $i++) {
$a[$i] = 54*$i;
$stringVersion .= $a[$i] . ',';
}
echo $stringVersion;
and here's a JS alternative
var a = [];
var stringVersion = '';
for(var i=1;i<=1000; i++) {
a[i] = 54*i;
stringVersion += a[i] + ',';
}
alert(stringVersion);
Something like this:
var array = new Array(1000);
for(var i=1;i<=1000;i++) {
array[i] = 54*i;
}
alert(array[1000]) ;
Just a few "pointers" (pun unintended);
Hope it helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.