Heim > Backend-Entwicklung > PHP-Tutorial > php中怎么输出javascript数组?

php中怎么输出javascript数组?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-06 20:49:14
Original
1410 Leute haben es durchsucht

php数组怎么输出成javascript中下面images值得样子?php数组中是url图片路径。 PHP数组格式为:

<code>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',
        });
</code>
Nach dem Login kopieren
Nach dem Login kopieren

这个问题已被关闭,原因:

回复内容:

php数组怎么输出成javascript中下面images值得样子?php数组中是url图片路径。 PHP数组格式为:

<code>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',
        });
</code>
Nach dem Login kopieren
Nach dem Login kopieren

你要是想输出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']
那就拼一下字符串就好了

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

php中怎么输出javascript数组?

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

<code>$array = ('a', 'b', 'c');
$array = array_map(create_function('$a', 'return "\"$a\"";'), $array);
$arr_js = '['.implde(',', $array).']';
</code>
Nach dem Login kopieren

不过其实可以考虑输出成json前段获取调用就是了。

<code><?php echo json_encode($images); ?>
</code>
Nach dem Login kopieren

是要输出Json字符串吗? 编码用json_encode($array) 解码用json_decode()

郁闷了,还是不成。到底怎么办呢?php啊

Verwandte Etiketten:
php
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
PHP-Datenerfassung?
Aus 1970-01-01 08:00:00
0
0
0
PHP-Erweiterung intl
Aus 1970-01-01 08:00:00
0
0
0
Wie man PHP gut lernt
Aus 1970-01-01 08:00:00
0
0
0
Mehrere PHP-Versionen
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage