CKTIS / PHP
Parola chiave elseif
Verifica una nuova condizione dopo il fallimento delle precedenti.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
if ($a): /* first */ elseif ($b): /* second */ endif;Verifica una nuova condizione dopo il fallimento delle precedenti. Vince la prima vera e le successive sono saltate. La sintassi con i due punti richiede la parola elseif, la forma else if ammessa con le graffe qui non va bene.
function band(int $n): string { if($n>=10): return "high"; elseif($n>=5): return "mid"; else: return "low"; endif; }
echo json_encode([band(12),band(7),band(2)]);
["high","mid","low"]
Esempi
<?php
function band(int $n): string { if($n>=10): return "high"; elseif($n>=5): return "mid"; else: return "low"; endif; }
echo json_encode([band(12),band(7),band(2)]);
Risultato
["high","mid","low"]