mirror of
https://github.com/php/doc-en.git
synced 2026-03-27 17:22:10 +01:00
Fix #79111: is_numeric documentation utterly incomplete
We add information about leading and trailing whitespace. Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de> Closes GH-870.
This commit is contained in:
committed by
Christoph M. Becker
parent
c1f8c2ea33
commit
ff054fcb4e
@@ -104,6 +104,73 @@ NULL is NOT numeric
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<example>
|
||||
<title><function>is_numeric</function> with whitespace</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$tests = [
|
||||
" 42",
|
||||
"42 ",
|
||||
" 9001", // non-breaking space
|
||||
"9001 ", // non-breaking space
|
||||
];
|
||||
|
||||
foreach ($tests as $element) {
|
||||
if (is_numeric($element)) {
|
||||
echo var_export($element, true) . " is numeric", PHP_EOL;
|
||||
} else {
|
||||
echo var_export($element, true) . " is NOT numeric", PHP_EOL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs.8;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
' 42' is numeric
|
||||
'42 ' is numeric
|
||||
' 9001' is NOT numeric
|
||||
'9001 ' is NOT numeric
|
||||
]]>
|
||||
</screen>
|
||||
&example.outputs.7;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
' 42' is numeric
|
||||
'42 ' is NOT numeric
|
||||
' 9001' is NOT numeric
|
||||
'9001 ' is NOT numeric
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="changelog">
|
||||
&reftitle.changelog;
|
||||
<informaltable>
|
||||
<tgroup cols="2">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>&Version;</entry>
|
||||
<entry>&Description;</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>8.0.0</entry>
|
||||
<entry>
|
||||
Numeric strings ending with whitespace (<literal>"42 "</literal>) will now
|
||||
return &true;. Previously, &false; was return instead.
|
||||
</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="seealso">
|
||||
|
||||
Reference in New Issue
Block a user