This question already has an answer here:
这个问题已经有了答案:
- How to append something to an array? 29 answers
- 如何在数组中附加一些东西?29日答案
Is it possible to store variables into arrays? What is the correct way of doing it? I can't seem to be able to store it in this way.
是否可能将变量存储到数组中?正确的做法是什么?我似乎不能这样保存它。
var fxVal = '<?php echo $fxVal;?>';
var equitiesVal = '<?php echo $equitiesVal;?>';
var boVal = '<?php echo $boVal;?>';
var balance = '<?php echo $account_balance;?>';
var myData = [fxVal,equitiesVal,boVal,balance];
2 个解决方案
#1
15
There are several ways to do it:
有几种方法可以做到:
var array1 = [var1, var2, var3, var4];
var array2 = new Array(var1, var2, var3, var4);
or
或
var array3 = new Array;
array3.push(var1);
array3.push(var2);
array3.push(var3);
array3.push(var4);
Have fun!
玩得开心!
#2
0
Take a look into JSON as data format.
查看JSON作为数据格式。
var data = <?= json_encode([$fxVal, $equitiesVal, $boVal, $account_balance]); ?>;
When you want to send or receive more data consider using AJAX.
当您希望发送或接收更多数据时,请考虑使用AJAX。
#1
15
There are several ways to do it:
有几种方法可以做到:
var array1 = [var1, var2, var3, var4];
var array2 = new Array(var1, var2, var3, var4);
or
或
var array3 = new Array;
array3.push(var1);
array3.push(var2);
array3.push(var3);
array3.push(var4);
Have fun!
玩得开心!
#2
0
Take a look into JSON as data format.
查看JSON作为数据格式。
var data = <?= json_encode([$fxVal, $equitiesVal, $boVal, $account_balance]); ?>;
When you want to send or receive more data consider using AJAX.
当您希望发送或接收更多数据时,请考虑使用AJAX。