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(){ | |
echo 'Olá'; | |
} | |
$saudacao = function(){ | |
echo 'Olá'; | |
}; |
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 | |
$cores = array( | |
array('cor' => 'verde'), | |
array('cor' => 'vermelho'), | |
array('cor' => 'amarelo') | |
); | |
usort($cores, function($a, $b){ | |
return strcmp($a['cor'], $b['cor']); | |
} |
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 | |
$em->getConnection()->beginTransaction(); | |
try{ | |
//... | |
$em->persist($user); | |
$em->flush(); | |
$em->getConnection()->commit(); | |
}catch(Exception $e){ | |
$em->getConnection()->rollback(); |
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 | |
$em->transactional(function($em){ | |
//... | |
$em->persist($user); | |
} |
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 | |
$input = 'Raphael'; | |
if(!empty($input)){ | |
echo $input; | |
}else{ | |
echo 'Vazio' . "\n\r"; | |
} |
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 | |
$input = 'Raphael'; | |
if(!empty($input)){ | |
echo $input; | |
}else{ | |
echo 'Vazio' . "\n\r"; | |
} |
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 Foo{ | |
protected static function speak(){ | |
echo __METHOD__, "\n\r"; | |
return 'Hi'; | |
} | |
public static function sayHi(){ | |
//return self::speak(); // PHP 5.2 <= |
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 | |
$lista = array(1, 3, 5, 7, 56, 65, 96, 244, 700, 892); | |
$filtro100 = function ($x){ | |
return $x > 100; | |
}; | |
$filtro50 = function ($x){ | |
return $x > 50; |
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 | |
$lista = array(1, 3, 5, 7, 56, 65, 96, 244, 700, 892); | |
function criarFiltro($maiorQue){ | |
return function ($x) use ($maiorQue){ | |
return $x > $maiorQue; | |
}; | |
} | |
$filtro100 = criarFiltro(100); |
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 | |
$lista = array(1, 3, 5, 7, 56, 65, 96, 244, 700, 892); | |
function criarFiltro($maiorQue){ | |
return function ($x) use ($maiorQue){ | |
return $x > $maiorQue; | |
}; | |
} | |
$filtro100 = criarFiltro(100); |