php数组怎么输出成javascript中下面images值得样子?php数组中是url图片路径。php数组格式为:
array([0] => http://xxx/xgsyw/content/uploads/img/1111.jpg[1] => http://xxx/xgsyw/content/uploads/img/222.jpg)$('#top').bgstretcher({ images: ['images/sample-1.jpg', 'images/sample-2.jpg', 'images/sample-3.jpg', 'images/sample-4.jpg', 'images/sample-5.jpg', 'images/sample-6.jpg'], slidedirection: 'n', slideshowspeed: 1000, transitioneffect: 'fade', sequencemode: 'normal', });
这个问题已被关闭,原因:
回复内容: php数组怎么输出成javascript中下面images值得样子?php数组中是url图片路径。php数组格式为:
array([0] => http://xxx/xgsyw/content/uploads/img/1111.jpg[1] => http://xxx/xgsyw/content/uploads/img/222.jpg)$('#top').bgstretcher({ images: ['images/sample-1.jpg', 'images/sample-2.jpg', 'images/sample-3.jpg', 'images/sample-4.jpg', 'images/sample-5.jpg', 'images/sample-6.jpg'], slidedirection: 'n', slideshowspeed: 1000, transitioneffect: 'fade', sequencemode: 'normal', });
你要是想输出json,php里json_encode是把数组转换成json,json_decode是把json转换成数组。肯定是可以用的,你可以说一下你遇到的具体问题。
你如果只是想输出你提到的
images: ['images/sample-1.jpg', 'images/sample-2.jpg', 'images/sample-3.jpg', 'images/sample-4.jpg', 'images/sample-5.jpg', 'images/sample-6.jpg']那就拼一下字符串就好了你给的那一段为什么会报错呢,那不就是申明一个数组么。回复里不能贴图,我就加在这里了。
拼接的话看看这样可以么?
$array = ('a', 'b', 'c');$array = array_map(create_function('$a', 'return \$a\;'), $array);$arr_js = '['.implde(',', $array).']';
不过其实可以考虑输出成json前段获取调用就是了。
是要输出json字符串吗?编码用json_encode($array)解码用json_decode()
郁闷了,还是不成。到底怎么办呢?php啊