<?php
$scores = [70, 90, 80];
foreach($scores as $key => $value){
echo “Score{{$key}}: {$value}” . PHP_EOL;
}
<?php
$scores = [70, 90, 80];
foreach($scores as $key => $value){
echo “Score{{$key}}: {$value}” . PHP_EOL;
}
<?php
// $scores = [70, 90, 80];
// $firstScore = $scores[0];
// $secondScore = $scores[1];
// $thirdScore = $scores[2];
// list($firstScore, $secondScore, $thirdScore) = $scores;
// [$firstScore, $secondScore, $thirdScore] = $scores;
// echo $firstScore . PHP_EOL;
// echo $secondScore . PHP_EOL;
// echo $thirdScore . PHP_EOL;
$x = 10;
$y = 20;
[$y, $x] = [$x, $y];
echo $x . PHP_EOL;
echo $y . PHP_EOL;
<?php
$scores = [70, 90, 80];
// sort($scores);
// print_r($scores);
// rsort($scores);
// print_r($scores);
// asort($scores);
// print_r($scores);
// arsort($scores);
// print_r($scores);
// shuffle($scores);
// print_r($scores);
$reversed = array_reverse($scores);
print_r($reversed);
<?php
$scores = [70, 90, 80];
array_splice($scores, 1, 0, [30, 20]);
array_splice($scores, 2, 1);
$removedItems = array_splice($scores, 1, 1, [10, 15]);
print_r($scores);
print_r($removedItems);
<?php
$scores = [70, 90, 80];
$scores[] = 60;
$moreScores = [10, 20, 30, ...$scores];
print_r($moreScores);
<?php
$names = ["Taro", "Jiro", "Saburo"];
echo array_search("Jiro", $names) .PHP_EOL;
<?php
$scores = [70, 90, 80];
// echo $scores[0] . PHP_EOL;
// $scores[1] = 95;
// echo $scores[1] . PHP_EOL;
var_dump($scores);
print_r($scores);
<?php
// function triple($num)
// {
// return $num * 3;
// }
// $triple = function($num)
// {
// return $num * 3;
// };
$triple = fn($num) => $num * 3;
echo $triple(10) . PHP_EOL;
<?php
function showAd()
{
echo "---------" . PHP_EOL;
echo "SALE! 50% OFF!" . PHP_EOL;
echo "---------" . PHP_EOL;
}
function showContent()
{
echo "BREAKING NEWS!" . PHP_EOL;
echo "Two baby pandas born at our Zoo!" . PHP_EOL;
}
showAd();
showContent();
showAd();
<?php
function printMessage($from, $to)
{
echo "Hi {$to}! from { $from}" . PHP_EOL;
}
printMessage(from: "Taro", to: "Jiro");
printMessage(to: "Shiro", from: "Saburo");