This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| A Vida do ElePHPante | |
| Tom: F | |
| C F | |
| PHPê, PHPê, | |
| C F | |
| PHPê, PHPê, PHPê (bis) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function quicksort(Array $array) { | |
| if (count($array) <= 1) return $array; | |
| $p = current($array); | |
| $less = array_filter($array, function($n) use ($p) { return $n < $p; }); | |
| $greater = array_filter($array, function($n) use ($p) { return $n > $p; }); | |
| return array_merge(quicksort($less), [$p], quicksort($greater)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $cpf = '76554323455'; | |
| echo strtr('012.345.678-910', str_split($cpf)); //765.543.234-55 | |
| $cnpj = '09876456000178'; | |
| echo strtr('01.234.567/891011-1213', str_split($cnpj)); ///09.876.456/0001-78 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Singleton | |
| { | |
| protected static $instance; | |
| public $texto = 'Padrão'; | |
| private function __construct() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $fib = function ($n) use (&$fib) { | |
| if (1 === $n || 2 === $n) | |
| return 1; | |
| return $fib($n - 1) + $fib($n - 2); | |
| }; | |
| echo $fib(10); // Output: 55 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Exercício – Números bonitos: | |
| * | |
| * Números são bonitos se contiverem um dígito 4 | |
| * e não contiverem um dígito 9. Quais números entre 14063 and 24779, | |
| * são bonitos? | |
| **/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Digitar o seguinte comando no console/cmd/ms-dos: | |
| php -S localhost:8000 | |
| /** Output | |
| PHP 5.5.3 Development Server started at Sun May 11 11:36:43 2014 | |
| Listening on http://localhost:8000 | |
| Document root is /Users/jweber | |
| Press Ctrl-C to quit. | |
| **/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $a = 50; // decimal | |
| $b = -123; // número negativo | |
| $c = 0123; // octal (83 decimal) | |
| $d = 0x1A; // número hexadecimal (26 decimal) | |
| $e = 1.234; // ponto flutuante | |
| $f = 1.2e3; // 1,2 x 1000 = 1200 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $x = true; | |
| $y = false; | |
| $a = (50 == '50'); // true | |
| $b = (50 === '50'); // false (tipo e valor) | |
| $c = (50 != '50'); // false | |
| $d = (50 !== '50'); // true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $numero = 30; | |
| echo $numero > 20 ? 'maior que 20' : 'menor ou igual a 20'; | |
| /** Output | |
| maior que 20 | |
| **/ |