将php数组解析为javascript [英] parsing php array to javascript

查看:69
本文介绍了将php数组解析为javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将php数组解析为javascript,但我发现javascript数组中只有一个数组元素存在。这是我的代码代码

Am trying to parse a php array into javascript but i found that only one element of the array was present in the javascript array. here is my code code

展开 | 选择 | Wrap | 行号

推荐答案

问题是Javascript数组有点不同于PHP数组。 Javascript数组使用仅数字值作为键。换句话说,Javascript中没有关联数组这样的东西。


Javascript中的关联数组称为:object。你有几个选项来定义(标准)对象

- 使用Object Literal
the problem is that a Javascript array is somewhat different from a PHP array. a Javascript array uses only numeric values as key. or put in other words, there is no such thing as an associative array in Javascript.

an associative array in Javascript is called: object. you have several options to define a (standard) object
- using the Object Literal
< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号


我想我理解第一个和最后一个选项,但数组是由数据库中的表中的值生成的,我无法控制数组的大小,更糟糕的是我不认为javascript具有foreach循环等效
i think i uderstand the 1st and last options but the array is being generated by values from a table in the database and i have no control over the size of the array and worse i dont think javascript have the foreach loop equivalent


< STRONG> @f礁石
错误


然而,这没关系。因为PHP在JavaScript启动时已经完成执行,所以你必须通过PHP打印每个键 - 值组合(使用方法1或3(2表示完整性))
@freefony
wrong.

nevertheless, it doesn?t matter. since PHP long finished execution when JavaScript starts, you have to print each and every key - value combination by PHP (using method 1 or 3 (2 was for completeness))


这篇关于将php数组解析为javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆