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前段获取调用就是了。
易通(企业网站管理系统)是一款小巧,高效,人性化的企业建站程序.易通企业网站程序是国内首款免费提供模板的企业网站系统.§ 简约的界面及小巧的体积:后台菜单完全可以修改成自己最需要最高效的形式;大部分操作都集中在下拉列表框中,以节省更多版面来显示更有价值的数据;数据的显示以Javascript数组类型来输出,减少数据的传输量,加快传输速度。 § 灵活的模板标签及模
0
立即学习“PHP免费学习笔记(深入)”;
<?php echo json_encode($images); ?>
是要输出Json字符串吗?
编码用json_encode($array)
解码用json_decode()
郁闷了,还是不成。到底怎么办呢?php啊
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号