gpt4 book ai didi

php - 如何将php数组转换为js数组?

转载 作者:行者123 更新时间:2023-12-02 18:38:47 38 4
gpt4 key购买 nike

我有一个 php 数组,需要对其进行转换并将其分配给 varlocationsArray

所需格式:

var locationsArray = [
['Google Official','1600 Amphitheatre Parkway, Mountain View, USA'],
['Google 1','112 S. Main St., Ann Arbor, USA'],
['Google 2','10 10th Street NE, Suite 600 USA']
];

最佳答案

    foreach ($address as $key => $val){
$val = strip_tags($val);
$points[] = array($val, $val);
}
$json = json_encode($points);
$json = str_replace('\n',' ',$json);
$json = str_replace('\r',' ',$json);

var locations = '<?php echo $json;?>';
var locations_array = JSON.parse(locations);

var locationsArray = locations_array;

关于php - 如何将php数组转换为js数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17037612/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com