PHPã®foræã使ã£ã課é¡ä¸è¦§
ããã°ã©ãã³ã°è¨èªãPHPãã®foræã使ã£ã課é¡ã¨åçï¼ãµã³ãã«ããã°ã©ã ï¼ã®ä¸ä¾ã¾ã¨ãã«ãªãã¾ãã
以ä¸ã®ããã°ã©ã ãä½æãã¦ãã ããã
ã課é¡1ã1ãã100ã¾ã§ã®æ´æ°ãé çªã«è¡¨ç¤ºããforæãä½æãã¦ãã ããã
for ($i = 1; $i <= 100; $i++) { echo $i; }
ã課é¡2ã1ãã100ã¾ã§ã®3ã®åæ°ã®ã¿ã表示ããforæãä½æãã¦ãã ããã
for ($i = 1; $i <= 100; $i++) { if ($i % 3 == 0) { echo $i; } }
ã課é¡3ãé
å$fruitsã«ãæç©ã®ååãæ ¼ç´ããforæã使ã£ã¦ä¸ã¤ãã¤è¡¨ç¤ºãã¦ãã ããã
$fruits = array("apple", "banana", "orange", "grape"); for ($i = 0; $i < count($fruits); $i++) { echo $fruits[$i]; }
ã課é¡4ã1ãã10ã¾ã§ã®æ´æ°ã®è¶³ãç®ã®çµæã表示ãã¦ãã ãã
$sum = 0; for ($i = 1; $i <= 10; $i++) { $sum += $i; } echo $sum;
ã課é¡5ãé
å$numbersã«ãæ´æ°ãæ ¼ç´ããforæã使ã£ã¦é
åã®ä¸èº«ã足ãç®ããçµæã表示ãã¦ãã ããã
$numbers = array(1, 2, 3, 4, 5); $sum = 0; for ($i = 0; $i < count($numbers); $i++) { $sum += $numbers[$i]; } echo $sum;
ã課é¡5ãé
å$numbersã«ãæ´æ°ãæ ¼ç´ããforæã使ã£ã¦é
åã®ä¸èº«ã足ãç®ããçµæã表示ãã¦ãã ããã
$numbers = array(1, 2, 3, 4, 5); $sum = 0; for ($i = 0; $i < count($numbers); $i++) { $sum += $numbers[$i]; } echo $sum;
ã課é¡6ã1ãã100ã¾ã§ã®æ´æ°ã®ãã¡ã3ã®åæ°ã¨5ã®åæ°ãé¤ããæ°åã表示ãã¦ãã ããã
for ($i = 1; $i <= 100; $i++) { if ($i % 3 == 0 || $i % 5 == 0) { continue; } echo $i; }
ã課é¡7ãé
å$studentsã«ãçå¾ã®ååãæ ¼ç´ããforæã使ã£ã¦é
åãå転ããååãä¸ã¤ãã¤è¡¨ç¤ºãã¦ãã ããã
$students = array("John", "Mary", "Bob", "Lisa");
$length = count($students);
for ($i = $length-1; $i >=0; $i--) {
echo $students[$i];
}
ã課é¡8ã2ãã20ã¾ã§ã®æ´æ°ã®ãã¡ãç´ æ°ã表示ãã¦ãã ãã
for ($i = 2; $i <= 20; $i++) { $isPrime = true; for ($j = 2; $j < $i; $j++) { if ($i % $j == 0) { $isPrime = false; break; } } if ($isPrime) { echo $i; } }
ã課é¡9ãé
å$scoresã«ãæ´æ°ãæ ¼ç´ããforæã使ã£ã¦é
åã®ä¸èº«ãå転ããä¸ã¤ãã¤è¡¨ç¤ºãã¦ãã ããã
$scores = array(10, 20, 30, 40, 50);
$length = count($scores);
for ($i = $length-1; $i >= 0; $i--) {
echo $scores[$i];
}
ã課é¡10ã1ãã100ã¾ã§ã®æ´æ°ã®ãã¡ãFizzBuzzã¨è¡¨ç¤ºãã¾ãã3ã®åæ°ã®æã¯Fizzã5ã®åæ°ã®æã¯Buzzã3ã®åæ°ãã¤5ã®åæ°ã®æã¯FizzBuzzã¨è¡¨ç¤ºãã¾ãã
for ($i = 1; $i <= 100; $i++) { if ($i % 3 == 0 && $i % 5 == 0) { echo "FizzBuzz"; } elseif ($i % 3 == 0) { echo "Fizz"; } elseif ($i % 5 == 0) { echo "Buzz"; } else { echo $i; } }
PHP7ãããã
PHP7ã¯é度ãã¯ãããªããã¡
ã¯ã¦ãªããã°ã§ã§ãããã¨ã¨ã使ã£ã¦ã¿ãææ³
ã¯ã¦ãªããã°ã5åã»ã©ä½¿ã£ã¦ã¿ãææ³ãééããããããã»ã»ã»ã
ã¯ã¦ãªããã°ã§ã§ãããã¨ã»ã§ããªããã¨
- ã«ãã´ãªã¼ãã¿ã°ãã¤ããããªãã
- è¨äºããµã¤ããã¼ã®HTMLãjavascriptãç·¨éãããã¨ãã§ããã
- è¨äºç·¨éï¼è¦ãã¾ã¾ç·¨éï¼ã§ã§ãããã¨ã¯ã太åãæä½ãææ¶æåãä¸ç·æåãæåã大ããããå°ããããå°ããããï¼font-sizeã10%ãã¤å¤æ´ãããï¼ãæåè²å¤æ´ããªã¹ããæ°åä»ããªã¹ãããªã³ã¯ãã¨ã·ã³ãã«ã
- Google AdSenseã®ã¢ã«ã¦ã³ããè¨å®ã§ããªãã
- ãµã¤ããã¼ã®"ãããã£ã¼ã«"ã"æ¤ç´¢"ã"ãªã³ã¯"ã¯æ¶ããã¨ãã§ããªããï¼ä½ç½®ã®ç§»åã¯å¯ï¼
- ãµã¤ããã¼ã«è¿½å ã§ããã¢ã¸ã¥ã¼ã«ã¯ç¡ããèªåã§HTMLãç·¨éãããã¨ã«ãªãã
- ç¸å¤ããããã¯ã¦ãªãã¼ã¯ã¼ãã«ãªã³ã¯ä»ãããã
- ãã¡ã¤ã³ã«ã¯ï¼hatenablog.comãhatenablog.jpãhateblo.jpãhatenadiary.comãhatenadiary.jpï¼ããé¸æå¯è½ã
- ãµããã¡ã¤ã³ãä»ããããã
- è¨äºä¸ããµã¤ããã¼ä¸¡æ¹ãããªã³ã¯ãä»ãããã¨ãã§ãããï¼ref="nofollow"ãä»ãã¦ããªãã®ã§ãSEOå¹æãè¦è¾¼ããï¼
ã¯ã¦ãªããã°ã使ã£ã¦ã¿ãææ³
æ®éã«ããã°ã¨ãã¦ä½¿ãåã«ã¯ä½¿ããããã®ã§ã¯ãªããã¨ãä½è¨ãªã¢ã¸ã¥ã¼ã«ï¼ã¢ã¯ã»ã¹ã«ã¦ã³ã¿ã¼ã¬ã¸ã§ããã¨ããããããã¤ï¼ãç¡ãã¦å人çã«ã¯å¥½æ触ã§ãããæ軽ã«æ©è½ãæ¡å¼µãããã¨ããã¦ã¼ã¶ã«ã¨ã£ã¦ã¯ã§ãããã¨ã¯å°ãªãã®ããããã¾ã®ã¨ãããGoogle AdSenseã®ã¢ã«ã¦ã³ãè¨å®ãªã©ã¯ã§ãã¾ããããrel="nofollow"ç¡ãã§ãªã³ã¯ãä»ãããã¨ãã§ããã®ã§SEOå¹æã¯è¦è¾¼ãã¾ããã¨ããããã§ãã·ã³ãã«ãªã¢ãã好ããªäººã«ã¯ãããã¨æãã¾ãï¼
PHPã«ããæååå¦ç
PHPã«ããæååå¦çã«ã¤ãã¦ãï¼ãã¹ããå·çä¸ã§ããï¼
æååé¢æ°
- substr() // æåååãåºã
- strlen() // æååã®é·ãï¼ãã¤ãï¼