php5.5 新特性

yield 关键字

<?php
function getNumberRange($start, $end, $step = 1) {
    while ($start <= $end) {
        yield $start;
        $start += $step;
    }
}


foreach (getNumberRange(1,100,2) as $number) {
    echo $number.',';
}
echo "\n";

finally 关键字

<?php
try {
    ...
} catch (Exception $ex) {
    ...
} finally {
    ...
}

新的加密

<?php

$password = 123456;

$hash = password_hash($password, PASSWORD_DEFAULT);
var_dump($hash);

var_dump(password_verify($password, $hash));

字符串和数组可以使用下标访问

<?php

var_dump([1,2,3,4,5][4]);

var_dump('dfdfdfdfdf'[4]);

foreach中使用list

<?php

$array = [
    [10, 20],
    [30, 40],
];
foreach ($array as list($a, $b)) {
    echo "First: $a; Second: $b\n";
}
comments powered by Disqus
Table of Contents