Skip to content

Instantly share code, notes, and snippets.

@alexeyshockov
Last active December 17, 2015 11:19
Show Gist options
  • Save alexeyshockov/5601737 to your computer and use it in GitHub Desktop.
Save alexeyshockov/5601737 to your computer and use it in GitHub Desktop.
Fucking PHP type system.
± phpsh
Starting php
type 'h' or 'help' to see instructions & features
php> $a = [1, 4, 3, true, false, 6, 0, 19]
php> =$a
array(
0 => 1,
1 => 4,
2 => 3,
3 => true,
4 => false,
5 => 6,
6 => 0,
7 => 19,
)
php> sort($a)
php> =$a
array(
0 => 0,
1 => false,
2 => 6,
3 => 19,
4 => true,
5 => 1,
6 => 3,
7 => 4,
)
php> sort($a)
php> =$a
array(
0 => 0,
1 => false,
2 => 1,
3 => 3,
4 => 4,
5 => 6,
6 => 19,
7 => true,
)
± phpsh
Starting php
type 'h' or 'help' to see instructions & features
php> $a = [1, 4, 3, 5, 10, 8, null, null, -1, -5]
php> =$a
array(
0 => 1,
1 => 4,
2 => 3,
3 => 5,
4 => 10,
5 => 8,
6 => null,
7 => null,
8 => -1,
9 => -5,
)
php> sort($a)
php> =$a
array(
0 => null,
1 => null,
2 => -5,
3 => -1,
4 => 1,
5 => 3,
6 => 4,
7 => 5,
8 => 8,
9 => 10,
)
php> usort($a, function($e1, $e2) { return $e1 - $e2; })
php> =$a
array(
0 => -5,
1 => -1,
2 => null,
3 => null,
4 => 1,
5 => 3,
6 => 4,
7 => 5,
8 => 8,
9 => 10,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment