I have two arrays (each with 1000 subarrays) which I merged.
Then I have to sort the new merged array and limit it to 1000 lines again.

Hier the codes:

```
$table1 = array(
    [0] => ('0' => 'A', '1' => 200),
    [1] => ('0' => 'B', '1' => 145),
    [2] => ('0' => 'C', '1' => 160),
    [3] => ('0' => 'D', '1' => 120),
    ...
    [999] => ('0' => 'Z', '1' => 135),
);

$table2 = array(
    [0] => ('0' => 'a', '1' => 20),
    [1] => ('0' => 'b', '1' => 145),
    [2] => ('0' => 'c', '1' => 500),
    [3] => ('0' => 'd', '1' => 600),
    ...
    [999] => ('0' => 'z', '1' => 135),
);

    // Merge arrays.
    $mergedTable = array_merge($table1,$table2);

```

and the result is:

```
$margedTable = array(
    [0] => ('0' => 'A', '1' => 200),
    [1] => ('0' => 'B', '1' => 145),
    [2] => ('0' => 'C', '1' => 160),
    [3] => ('0' => 'D', '1' => 120),
    ...
    [999] => ('0' => 'Z', '1' => 135),
    [1000] => ('0' => 'a', '1' => 20),
    [1001] => ('0' => 'b', '1' => 145),
    [1002] => ('0' => 'c', '1' => 500),
    [1003] => ('0' => 'd', '1' => 600),
    ...
    [1999] => ('0' => 'z', '1' => 135),
);

```

With that I have now an array with 2000 subarrays/lines.
I can sort or limit it separately, but I'm not able to do both operations together.

To limit it I could use array\_slice, but then I would have only the first 1000 lines and that's exactly the first array = $table1.

```
$limitedTable = array_slice($mergedTable, 0, 999);

```

to avoid that I have first to sort the merged array. I could do this with following function and usort:

```
function sortByOne($a, $b) {
    $a = $a['1'];
    $b = $b['1'];

    if ($a == $b) {
        return 0;
    }

    return ($a < $b) ? -1 : 1;
}

usort($mergedTable, 'sortByOne');

```

with that I have following result:

```
$margedTable = array(
    [1003] => ('0' => 'd', '1' => 600),
    [1002] => ('0' => 'c', '1' => 500),
    [0] => ('0' => 'A', '1' => 200),
    [2] => ('0' => 'C', '1' => 160),
    [1] => ('0' => 'B', '1' => 145),
    [1001] => ('0' => 'b', '1' => 145),
    [999] => ('0' => 'Z', '1' => 135),
    [1999] => ('0' => 'z', '1' => 135),
    [3] => ('0' => 'D', '1' => 120),
    ...
    [1000] => ('0' => 'a', '1' => 20),
);

```

In the reality the keys don't remain the same so we have following result (but that's ok):

```
$margedTable = array(
    [0] => ('0' => 'd', '1' => 600),
    [1] => ('0' => 'c', '1' => 500),
    [2] => ('0' => 'A', '1' => 200),
    [3] => ('0' => 'C', '1' => 160),
    [4] => ('0' => 'B', '1' => 145),
    [5] => ('0' => 'b', '1' => 145),
    [6] => ('0' => 'Z', '1' => 135),
    [7] => ('0' => 'z', '1' => 135),
    [8] => ('0' => 'D', '1' => 120),
    ...
    [1999] => ('0' => 'a', '1' => 20),
);

```

The problem now is that I cannot limit this one. I tried just like that, but then I receive a boolean (?) = 1

```
 $limitedTable = usort($mergedTable, 'sortByOne');

 print_r($limitedTable);

```

and the result = 1

I would appreciate any help.