Skip to content

Instantly share code, notes, and snippets.

@hayatravis
Last active August 29, 2015 14:07
Show Gist options
  • Save hayatravis/ecdad4c5017bdf68b929 to your computer and use it in GitHub Desktop.
Save hayatravis/ecdad4c5017bdf68b929 to your computer and use it in GitHub Desktop.
hhvm_hack
<?php
function test($max) {
for ($i = 1; $i <= $max; $i++) {
if ($i <= 1) {
continue;
}
if ($i == 2) {
print $i . "\n";
continue;
}
if ($i % 2 == 0) {
continue;
}
$flg = false;
for ($j =3; $j < $i; $j++) {
if ($i % $j == 0) {
$flg = true;
break;
}
}
if ($flg === false) {
print $i . "\n";
}
}
}
$start = microtime(true);
test(10000);
echo (microtime(true) - $start) * 1000 . "ms\n";
<?php
function test(): void {
$sum = 0;
for ($i=1;$<=10;$i++) {
$sum += $i;
echo $sum . "\n";
}
}
test();
<?php
// 型指定 nullable
function add_one($i) {
return $int + 1;
}
// Vector
$vector = Vector<int> { 100, 200, 400};
$vector[] = 500; // 追加
$vector[0] = 111; // 上書き
$vector->get(1);
// Vector::filter
$vector = Vector<int> { 100, 200, 400};
$v_filter = $vector->filter(function($v) {
return 150 <= $v;
});
// Map
$map = Map {"a" => 10, "b" => 20, "c" => 30};
$map['d'] = 40; // 追加
$map['a'] = 111; // 上書き
$map->get('a');
// Map::contains, Map::filterWithKey
$map->contains('a');
$v_map = $map->filterWithKey(function($k, $v) {
return ($k === 'b' || $k === 'c');
});
// Lambda
$foo = $x ==> $x + 1;
echo $foo(12) . "\n";
$squared = array_map($x ==> $x*$x, array(1,2,3));
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
<link rel="shortcut icon" href="">
</head>
<body>
<h1>テスト</h1>
<?php foreach (array(1, 2, 3, 4) as $num): ?>
<p><?php echo $num; ?></p>
<?php endforeach; ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment