gpt4 book ai didi

javascript - 如何创建嵌套数组

转载 作者:行者123 更新时间:2023-11-28 18:23:28 25 4
gpt4 key购买 nike

我需要构建一个如下所示的数组,当您在 javascript 中进行 JSON.stringify 时,它看起来与此类似。怎么办,请帮忙

     [{
name: 'Microsoft Internet Explorer',
id: 'Microsoft Internet Explorer',
data:[
['v11.0', 24.13],
['v8.0', 17.2],
['v9.0', 8.11],
['v10.0', 5.33],
['v6.0', 1.06],
['v7.0', 0.5]
]}

正确的做法是怎样的?

$arr[] = array('name' => 'example', 'y' => 25, 'drill' => 'test', 'data :' => 
'["test" =>25]' );

print_r $arr;

此外,我在代码的其他部分执行了此操作,但它不是嵌套的。我无法再次执行此操作,因为内部数组内部的逗号很难删除。

最佳答案

$array = []; 

$test = new stdClass();
$test->name = "Name";
$test->id = "Id";
$test->data = array("val1", "val2", "val3");

$array[] = $test;

echo json_encode($array); // [{"name":"Name","id":"Id","data":["val1","val2","val3"]}]

关于javascript - 如何创建嵌套数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39552476/

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