Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Sort an array in ascending order
<?php sort(array &$array, int $flags = SORT_REGULAR): true
<?php } else {
$descending
? rsort($array, $options)
: sort($array, $options);
}
return $array;
<?php if (preg_match('/(?P<imports>(?:^use [^;{]+;$\n?)+)/m', $stub, $match)) {
$imports = explode("\n", trim($match['imports']));
sort($imports);
return str_replace(trim($match['imports']), implode("\n", $imports), $stub);
}
<?php sort($segments);
return strtolower(implode('_', $segments));
}
<?php }
}
sort($keys);
return array_values(array_unique($keys));
}
<?php {
$input = range('a', 'z');
$shuffled = Arr::shuffle($input);
sort($shuffled);
$this->assertEquals($input, $shuffled);
}
<?php $data = new $collection([['item' => '1'], ['item' => '10'], ['item' => 5], ['item' => 20]]);
$expected = $data->pluck('item')->toArray();
sort($expected);
$data = $data->sortBy(['item']);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
<?php $data = $data->sortBy([['item', 'desc']]);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
sort($expected, SORT_STRING);
$data = $data->sortBy(['item'], SORT_STRING);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
<?php $data = $data->sortBy([['item', 'desc']], SORT_STRING);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
sort($expected, SORT_NUMERIC);
$data = $data->sortBy(['item'], SORT_NUMERIC);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
<?php $data = new $collection([['item' => 'img1'], ['item' => 'img101'], ['item' => 'img10'], ['item' => 'img11']]);
$expected = $data->pluck('item')->toArray();
sort($expected, SORT_NUMERIC);
$data = $data->sortBy(['item'], SORT_NUMERIC);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
<?php $data = $data->sortBy(['item'], SORT_NUMERIC);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
sort($expected);
$data = $data->sortBy(['item']);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
<?php $data = $data->sortBy(['item']);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
sort($expected, SORT_NATURAL);
$data = $data->sortBy(['item'], SORT_NATURAL);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
<?php $data = new $collection([['item' => 'img1'], ['item' => 'Img101'], ['item' => 'img10'], ['item' => 'Img11']]);
$expected = $data->pluck('item')->toArray();
sort($expected);
$data = $data->sortBy(['item']);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
<?php $data = $data->sortBy(['item']);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
sort($expected, SORT_NATURAL | SORT_FLAG_CASE);
$data = $data->sortBy(['item'], SORT_NATURAL | SORT_FLAG_CASE);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
<?php $data = $data->sortBy(['item'], SORT_NATURAL | SORT_FLAG_CASE);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
sort($expected, SORT_FLAG_CASE | SORT_STRING);
$data = $data->sortBy(['item'], SORT_FLAG_CASE | SORT_STRING);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
<?php $data = $data->sortBy(['item'], SORT_FLAG_CASE | SORT_STRING);
$this->assertEquals($data->pluck('item')->toArray(), $expected);
sort($expected, SORT_FLAG_CASE | SORT_NUMERIC);
$data = $data->sortBy(['item'], SORT_FLAG_CASE | SORT_NUMERIC);
$this->assertEquals($data->pluck('item')->toArray(), $expected);