PHPのifをJavaScriptのifの結果と同じにするサンプル

実際にJavaScriptおよびPHPで結果を出力しています。

const r1 = document.getElementById('resultJS1')
const r2 = document.getElementById('resultJS2')

if ('0') {
  r1.textContent = true
} else {
  r1.textContent = false
}

if (Array()) {
  r2.textContent = true
} else {
  r2.textContent = false
}

if ('0'):

if (Array()):

$var = '0';
if ($var || $var === '0') {
  echo "<p>if ('0'): true</p>";
} else {
  echo "<p>if ('0'): false</p>";
}

$arr = array();
if (is_array($arr)) {
  echo "<p>if (array()): true</p>";
} else {
  echo "<p>if (array()): false</p>";
}

if ($var || $var === '0'): true

if (is_array($arr)): true

元記事を表示する