如何在php中设置动态数组名称
您好,我正在尝试使用动态数组名称。但是当我运行此代码时,我收到错误 $marker is undefined
。
if (isset($arr)) {
foreach ($arr as $key => $value) {
$marker.$key = array();
$marker.$key ['position'] = $value['lat'] . ',' . $value['long'];
$marker.$key ['draggable'] = 'TRUE';
$marker.$key ['ondragend'] = "test(this.getPosition().lat(),this.getPosition().lng())";
$this->ci->googlemaps->add_marker($marker.$key);
$i++;
}
}
我如何创建动态数组名称???
hi i am trying to use dynamic array name . but when i run this code i get the error $marker is undefined
.
if (isset($arr)) {
foreach ($arr as $key => $value) {
$marker.$key = array();
$marker.$key ['position'] = $value['lat'] . ',' . $value['long'];
$marker.$key ['draggable'] = 'TRUE';
$marker.$key ['ondragend'] = "test(this.getPosition().lat(),this.getPosition().lng())";
$this->ci->googlemaps->add_marker($marker.$key);
$i++;
}
}
how can i create dynamic array name ????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
阅读精美手册。 PHP 中的点运算符与 Javascript 和类似语言中的点运算符完全无关 - 它执行字符串连接。我不太明白你想要做什么,但我相当确定字符串连接不是它。
澄清一下,这是做什么的:
...是这个;
$marker
中的值,将其解释为字符串$key
中的值,将其解释为连接$marker
和<的 code>$stringRead The Fine Manual. The dot operator in PHP is completely unrelated to the dot operator in Javascript and similar languages - it does string concatenation. I don't quite understand what it is you're trying to do, but I'm fairly sure string concatenation is not it.
To clarify, what this does:
...is this;
$marker
, interpret it as a string$key
, interpret it as a string$marker
and$string
试试这个,当你进行串联时,PHP 只看到 $key 是一个数组,并且以错误的方式串联。无论如何,$marker 是在哪里定义的?
Try this, when you do your concatenation PHP sees only $key to be an array, and concatenates the wrong way. Anyway, where is $marker defined??
Php中的动态数组名称可以这样完成
但是,您也可以这样做,设置数组变量
Dynamic array names in Php can be done like this
Yet, you can also do like this, to set the array-variable