by shigemk2

当面は技術的なことしか書かない

while のなかで変数を使う

whileの応用

whileのなかで変数を定義し、whileの中で
変数を利用することができる

<?php
$high = array();

for ($i = 0; $i < 10; $i++) {
  $high[] = $i;
 }

while (($low = (array_pop($high)))) {
  if(($low % 2) === 0) {
    print_r('high and low' . PHP_EOL);
  } else {
    print_r('hunting' . PHP_EOL);
  }
 }

結果

hunting
high and low
hunting
high and low
hunting
high and low
hunting
high and low
hunting