Q:

I want to sort the array by keys in php

I have an array, $data, in the form of :
Array
(
    [1] => Array
        (
            [group_exp] => Group 2
            [cat_exp] => Category 3
            [sub_exp] => Sub Category 4
        )
    [2] => Array
       (
            [group_exp] => Group 3
            [cat_exp] => Category 4
            [sub_exp] => Sub Category 5
       )

)

but i want to save this array in this form :
Array
(
    [0] => Array
        (
            [group_exp] => Group 2
            [cat_exp] => Category 3
            [sub_exp] => Sub Category 4
        )
    [1] => Array
       (
            [group_exp] => Group 3
            [cat_exp] => Category 4
            [sub_exp] => Sub Category 5
       )

)

A:

As the comments has shown, use array_values to reorder the indexes if the array already is in the correct order.
$array = array_values($array);

If the array should be sorted by its indices (if their inherent order is not sorted, such as [2], [1], [3], sort the array by key first:
ksort($array);
$array = array_values($array);

