<?php
$moreScores = [
55,
72,
‘perfect’,
[90, 42,88],
];
$scores = [
90,
40,
…$moreScores,
100,
];
//print_r($scores);
echo $scores[5][2] . PHP_EOL;
<?php
$moreScores = [
55,
72,
‘perfect’,
[90, 42,88],
];
$scores = [
90,
40,
…$moreScores,
100,
];
//print_r($scores);
echo $scores[5][2] . PHP_EOL;
<?php
$scores = [
‘first’ => 90,
‘second’ => 40,
‘third’ => 100,
];
//foreach($scores as $value){
//foreach($scores as $score){
// echo $score . PHP_EOL;
//}
foreach($scores as $key => $score){
echo $key .’ – ‘. $score . PHP_EOL;
}
<?php
//$score1 = 90;
//$score2 = 40;
//$score3 = 100;
$scores = [
90,
40,
100
];
$scores[1] = 60;
echo $scores[1] . PHP_EOL;
<?php
declare(strict_types=1);
function showInfo(string $name, int $score): void
{
echo $name . ‘: ‘ . $score . PHP_EOL;
}
//showInfo(‘chodome’, 40);
//showInfo(‘chodome’, ‘gamegank’);
showInfo(‘chodome’, ‘4’);
<?php
function sum($a, $b, $c)
{
$total = $a + $b + $c;
//if($total < 0){
// return 0;
// }else{
// return $total;
// }
return $total < 0 ? 0 : $total;
}
echo sum(100,300,500) . PHP_EOL; //900
echo sum(-1000,300,500) . PHP_EOL; //0
<?php
function sum($a, $b, $c)
{
return $a + $b + $c;
}
$sum = function($a, $b, $c){
return $a + $b + $c
};
echo $sum(100, 300, 500) .PHP_EOL;
<?php
function showAd()
{
echo ‘———-‘ . PHP_EOL;
echo ‘— Ad —‘ . PHP_EOL;
echo ‘———-‘ . PHP_EOL;
}
showAd();
echo ‘Tom is great!’ . PHP_EOL;
echo ‘Bob is great!’ . PHP_EOL;
showAd();
echo ‘Steve is great!’ . PHP_EOL;
echo ‘Bob is great!’ . PHP_EOL;
showAd();
<?php
function showAd()
{
echo ‘———-‘ . PHP_EOL;
echo ‘— Ad —‘ . PHP_EOL;
echo ‘———-‘ . PHP_EOL;
}
showAd();
echo ‘Tom is great!’ . PHP_EOL;
echo ‘Bob is great!’ . PHP_EOL;
showAd();
echo ‘Steve is great!’ . PHP_EOL;
echo ‘Bob is great!’ . PHP_EOL;
showAd();
<?php
for ($i = 1; $i <= 10; $i++) {
//if($i === 4){
//if($i % 3 === 0){
// continue;
//}
if($i === 4){
break;
}
echo $i . PHP_EOL;
}
<?php
// $hp = 100;
$hp = -50;
// while ($hp > 0) {
// echo “Your HP: $hp” . PHP_EOL;
// $hp -= 15;
// }
do {
echo “Your HP: $hp” . PHP_EOL;
$hp -= 15;
} while ($hp > 0);