删除php数组上的唯一索引

删除php数组上的唯一索引,php,json,Php,Json,当我使用php时,我试图在php上打印一个数组 echo json_encode($array); 它告诉我: { "1": { "x": "145", "y": "20" }, "2": { "x": "145", "y": "40" } } 但我想要这个: { { "x":"145", "y":"20" }, { "x

当我使用php时,我试图在php上打印一个数组

echo json_encode($array);
它告诉我:

{
    "1": {
        "x": "145",
        "y": "20"
    },
    "2": {
        "x": "145",
        "y": "40"
    }
}
但我想要这个:

{
    {
         "x":"145",
         "y":"20"
    },
    {
        "x":"145",
        "y":"40"
    }
}

如何做到这一点?

只需使用
array\u值

echo json_encode(array_values($array));

为了实现这一点,你需要像这样构造你的阵列

$arr = array(array("x"=>145, "y"=>20),array("x"=>145, "y"=>40));

这将为json_encode提供以下信息

[{"x":145,"y":20},{"x":145,"y":20}]

那么你怎么才能得到一个特定的索引值呢?你想要的json不是很有效,你有两个对象嵌套在另一个对象中$your_json它是一个数组而不是字符串我不是先生。很高兴它帮助了你。
[{"x":145,"y":20},{"x":145,"y":20}]
$newArray = array();
foreach ($array as $key => $val)
{
    $newArray[] = $val;
}

print_r(json_encode($newArray));

**Result**: [{"x":"145","y":"20"},{"x":"145","y":"40"}]