php怎么输出js,php中怎么输出javascript数组?

该博客讨论如何将PHP数组转换成JavaScript数组格式,特别是当数组包含图片URL时。提到了使用`json_encode`函数将PHP数组编码为JSON,然后在前端JavaScript中使用JSON.parse()解析。还探讨了字符串拼接的方法作为替代方案,并分享了尝试过程中的问题和解决方案。
摘要由CSDN通过智能技术生成

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']

那就拼一下字符串就好了

你给的那一段为什么会报错呢,那不就是申明一个数组么。回复里不能贴图,我就加在这里了。

951ee056f00b160996f8d9bf2fd7ad49.png

拼接的话看看这样可以么?

$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啊

相关标签:php

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值