如何删除数组的索引

时间:2018-01-04 14:20:16

标签: php arrays

以下是我的数组..我想删除起始数组的键,如0,1,2。

Array
(
    [0] => Array
        (
            [cart_id] => 71
            [product_id] => 33
            [u_id] => 7
            [size] => medium
            [color] => blue
            [quantity] => 1
            [vendor_id] => 4
            [country_id] => 1
            [product_category] => 1
            [product_name] => Black Dress
            [short_description] => Flying Doll Black Dress
            [detail_description] => lorem ipsum
            [price] => 2000
            [special_price] => 2000



        )

    [1] => Array
        (
            [cart_id] => 74
            [product_id] => 37
            [u_id] => 7
            [size] => medium
            [color] => blue
            [quantity] => 1
            [vendor_id] => 4
            [country_id] => 1
            [product_category] => 3
            [product_name] => Pink Skirt
            [short_description] => Lady Shop Skirt combo
            [detail_description] => lorem ipsum
            [price] => 3000
            [special_price] => 2100



        )

    [2] => Array
        (
            [cart_id] => 72
            [product_id] => 46
            [u_id] => 7
            [size] => medium
            [color] => blue
            [quantity] => 2
            [vendor_id] => 4
            [country_id] => 1
            [product_category] => 1
            [product_name] => Chirag
            [short_description] => Hello guys
            [detail_description] => How r u
            [price] => 200
            [special_price] => 120


        )
}

我想在启动数组之前删除[0]。[1],[2]。

我想要一个带有这些子数组的主数组,包括。

我对此没有更多的了解,有人知道,请帮助我谢谢。

我想从json out put

中删除0,1,2
{
    "status": true,
    "data": {
        "0": {
            "cart_id": "71",
            "product_id": "33",
            "u_id": "7",
            "size": "medium",
            "color": "blue",
            "quantity": "1",
            "vendor_id": "4",
            "country_id": "1",
            "product_category": "1",
            "product_name": "Black Dress",
            "short_description": "Flying Doll Black Dress",
            "detail_description": "lorem ipsum",
            "price": "2000",
            "special_price": "2000",
            "productImages": [
                {
                    "image_id": "2",
                    "image": "http://192.168.0.123/zerototwo/images/productimage/15136761291.jpg"
                },
                {
                    "image_id": "21",
                    "image": "http://192.168.0.123/zerototwo/images/productimage/15144618151.jpg"
                }
            ]
        },
        "1": {
            "cart_id": "74",
            "product_id": "37",
            "u_id": "7",
            "size": "medium",
            "color": "blue",
            "quantity": "1",
            "vendor_id": "4",
            "country_id": "1",
            "product_category": "3",
            "product_name": "Pink Skirt",
            "short_description": "Lady Shop Skirt combo",
            "detail_description": "lorem ipsum",
            "price": "3000",
            "special_price": "2100",
            "productImages": [
                {
                    "image_id": "8",
                    "image": "http://192.168.0.123/zerototwo/images/productimage/15136770031.jpg"
                },
                {
                    "image_id": "9",
                    "image": "http://192.168.0.123/zerototwo/images/productimage/15136770032.jpg"
                }
            ]
        },

Json生成代码

 header('Content-type: application/json');
        echo json_encode($response);

1 个答案:

答案 0 :(得分:-1)

试试这个

$response= [ 'status' => true, 'data' => array_values($data) ] ;
echo json_encode($response);