(PHP 4, PHP 5, PHP 7, PHP 8)
is_numeric — Verifica se una variabile è un numero o una stringa numerica
Verifica se una variabile è un numero. Le stringhe numeriche consistono in segni
opzionali, qualsiasi numero di cifre, parte decimale opzionale e parte esponenziale opzionale.
Quindi +0123.45e6
è un valore numerico valido. Le notazioni
Esadecimali (per esempio 0xf4c3b00c
), Binarie (per esempio 0b10100111001
),
Ottali (per esempio 0777
) non sono consentite.
var
La variabile da valutare.
Restituisce true
se var
è un numero o una stringa numerica,
false
in caso contrario.
Example #1 Esempi di is_numeric()
<?php
$tests = array(
"42",
1337,
0x539,
02471,
0b10100111001,
1337e0,
"not numeric",
array(),
9.1
);
foreach ($tests as $element) {
if (is_numeric($element)) {
echo "'{$element}' is numeric", PHP_EOL;
} else {
echo "'{$element}' is NOT numeric", PHP_EOL;
}
}
?>
Il precedente esempio visualizzerà:
'42' is numeric '1337' is numeric '1337' is numeric '1337' is numeric '1337' is numeric '1337' is numeric 'not numeric' is NOT numeric 'Array' is NOT numeric '9.1' is numeric
Versione | Descrizione |
---|---|
7.0.0 |
Le stringhe nella notazione esadecimale (per esempio 0xf4c3b00c ) non
sono più considerate come stringhe numeriche, ovvero
is_numeric() ora restituisce false .
|