Correcting teacher:Guanhui
Correction status:qualified
Teacher's comments:整体写的还行!尽量配上效果图,每个段落的标题注意一下!不要排乱了。
function sum(int $a, int $b): int
{
return $a + $b;
}
echo sum(10, 20);
function getPrice(float $money, float $discount): float
{
return $money * $discount;
}
echo '实付金额= ' . getPrice(1000, 0.9);
echo mb_substr($str, 0, 6);
$funcName = 'getPrice';
echo '实付金额= ' . $funcName(2000, 0.8), '<hr>';
$discount = 0.6;
$p = function (float $money, int $n) use ($discount): float {
return $money * $n * $discount;
};
echo '实付金额= ' . $p(4000, 2);
function demo1(): string
{
$status = 1;
$message = '成功';
return $status . ',' . $message;
}
echo demo1();
function demo3(): array
{
$status = 1;
$message = '成功';
return ['status' => $status, 'msg' => $message];
}
echo demo3();
function demo5(): string
{
$status = 1;
$message = '成功';
return json_encode(['status' => $status, 'msg' => $message]);
}
echo demo5();
function demo6(): string
{
$status = 1;
$message = '成功';
return serialize(['status' => $status, 'msg' => $message]);
}
echo demo6();
function demo8(): string
{
$status = 1;
$message = '成功';
return serialize(['status' => $status, 'msg' => $message]);
}
print_r(unserialize(demo8())['msg']);
function demo1(float $arg): float
{
return $arg *= 2;
}
echo demo1(80);
function demo2(float &$arg): float
{
return $arg *= 2;
}
$val = 80;
echo $val;
function demo3(float $a, float $b, string $opt = '+')
{
$res = 0;
switch ($opt) {
case '+':
$res = "$a + $b = " . ($a + $b);
break;
case '-':
$res = "$a - $b = " . ($a - $b);
break;
case '*':
$res = "$a * $b = " . ($a * $b);
break;
case '/':
$res = "$a / $b = " . ($a / $b);
break;
default:
$res = '非法操作符';
}
return $res;
}
echo demo3(5, 10), '<br>';
echo demo3(8, 9, '*'), '<br>';
echo demo3(8, 9, '@'), '<br>';
function demo4($a, $b, $c)
{
return $a + $b + $c;
}
echo demo4(1, 2, 3);
function demo5(...$args)
{
return array_sum($args);
}
$res = demo5(1, 2, 3, 4, 5, 6);
print_r($res);
function demo6(...$args)
{
return array_sum($args);
}
$arr = [1, 2, 3, 4, 5, 6, 7, 8];
$res = demo6(...$arr);
print_r($res);
$data = range(1, 100);
$arr = array_map(function ($item) {
if ($item % 2 === 0)
return $item;
}, $data);
print_r($arr);
$data = range(1, 100);
$arr = array_map(function ($item) {
if ($item % 2 === 0)
return $item;
}, $data);
$res = array_filter($arr, function ($item) {
return $item;
});
print_r(array_values($res));
namespace ns1 {
function demo1()
{
return __FUNCTION__;
}
}
namespace {
function demo1()
{
}
echo ns1\demo1();
}