<?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
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 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;
}
<foreach文>
複数の要素をもつものを順番に取り出してくれるループ文
foreach(仮の入れ物 in 取り出し元)
{
}
————————–
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour
{
void Start()
{
int[] a = {1,2,3,4,5};
foreach (int i in a)
{
Debug.Log(i);
}
}
// Update is called once per frame
void Update()
{
}
}
型[] 配列名 = new 型[要素数];
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour
{
void Start()
{
int[,,] a = new int[3,4,2];
for(int i = 0; i < a.GetLength(0); ++i)
{
for(int j = 0; j < a.GetLength(1); ++j)
{
for(int k = 0; k < a.GetLength(2); ++k)
{
a[i,j,k] = i + j + k;//代入
Debug.Log(“a[“+ i + “,” + j + “,” + k + “]に代入する”);
}
}
}
}
// Update is called once per frame
void Update()
{
}
}