Your app
Your app & dependencies
source http://code.tutsplus.com/
<?php
$input = array(1, 2, 3, 4, 5);
$output = array_filter($input, function ($v) {
return $v > 2;
});
$max_comparator = function ($v) {
return $v > 2;
};
$input = array(1, 2, 3, 4, 5);
$output = array_filter($input, $max_comparator);
<?php
trait MyTrait
{
public function doSomething($var)
{
return $var . ' does something';
}
}
class BaseController extends Controller
{
use MyTrait;
public function indexAction()
{
$this->doSomething('var');
}
}
<?php
function inverse($x)
{
if (!$x) {
throw new Exception('Division by zero.');
}
return 1 / $x;
}
try {
echo inverse(5);
} catch (Exception $e) {
echo 'Caught exception: ' . $e->getMessage();
} finally {
echo 'This is the last echo';
}
<?php
$array = array(
'foo' => 'bar',
'bar' => 'foo'
);
// as of PHP 5.4
$array = [
'foo' => 'bar',
'bar' => 'foo'
];
<?php
$hash = password_hash('rasmuslerdorf', PASSWORD_DEFAULT);
if (password_verify('rasmuslerdorf', $hash)) {
echo 'Password is valid!';
} else {
echo 'Invalid password.';
}
<?php
$items = [
['a', 'b', 'c', 'd'],
[1, 2, 3, 4]
];
foreach ($items as list($var1, $var2, $var3, $var4)) {
//
}
<?php
function add($a, $b, $c)
{
return $a + $b + $c;
}
// a very simple call
add(1, 2, 6);
// as of PHP 5.6
$numbers = [1, 2, 3];
add(...$numbers);