Home >Backend Development >PHP Tutorial >Determine whether it is a number, time format

Determine whether it is a number, time format

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 09:05:591142browse

is_numeric();

<code><span><span><?php</span><span>$tests</span> = <span>array</span>(
    <span>"42"</span>, 
    <span>1337</span>, 
    <span>"1e4"</span>, 
    <span>"not numeric"</span>, 
    <span>array</span>(), 
    <span>9.1</span>
);

<span>foreach</span> (<span>$tests</span><span>as</span><span>$element</span>) {
    <span>if</span> (is_numeric(<span>$element</span>)) {
        <span>echo</span><span>"'{$element}' is numeric"</span>, PHP_EOL;
    } <span>else</span> {
        <span>echo</span><span>"'{$element}' is NOT numeric"</span>, PHP_EOL;
    }
}
<span>?></span></span></code>

result

<code><span>'42'</span><span>is</span> numeric
<span>'1337'</span><span>is</span> numeric
<span>'1e4'</span><span>is</span> numeric
<span>'not numeric'</span><span>is</span><span>NOT</span> numeric
<span>'Array'</span><span>is</span><span>NOT</span> numeric
<span>'9.1'</span><span>is</span> numeric</code>

strtotime($time)

<code><span>$time</span> = <span>'2015adsasd'</span>;
var_dump(strtotime(<span>$time</span>));
<span>$time1</span> = <span>'2015-01-11'</span>;
var_dump(strtotime(<span>$time1</span>));</code>

result

<code><span>bool</span>(<span>false</span>)
<span>int</span>()</code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the judgment of whether it is a number and the time format, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn