note 105179 added to function.range
| From: | Ray dot Paseur at Gmail dot com | Date: | Mon, 01 Aug 2011 16:30:20 +0000 |
| Subject: | note 105179 added to function.range | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182078@lists.php.net to get a copy of this message | ||
Be VERY careful if you use range() to generate an array of numeric strings. Even though the input
is quoted, the resulting array contains integers, not strings.
<?php // RAY_temp_range.php
error_reporting(E_ALL);
// A RANGE OF NUMBERS
$numbrs = range("0", "9");
// AN ARRAY OF NUMERIC CHARACTERS
$alphas = array();
foreach ($numbrs as $n)
{
$alphas[] = "$n";
}
// THEY LOOK THE SAME
print_r($numbrs);
echo "<br/>";
print_r($alphas);
// BUT THEY ARE DIFFERENT
echo "<pre>";
var_dump($numbrs);
var_dump($alphas);
----
Server IP: 69.147.83.197
Probable Submitter: 98.169.58.122
----
Manual Page -- http://www.php.net/manual/en/function.range.php
Edit -- https://master.php.net/note/edit/105179
Del: integrated -- https://master.php.net/note/delete/105179/integrated
Del: useless -- https://master.php.net/note/delete/105179/useless
Del: bad code -- https://master.php.net/note/delete/105179/bad+code
Del: spam -- https://master.php.net/note/delete/105179/spam
Del: non-english -- https://master.php.net/note/delete/105179/non-english
Del: in docs -- https://master.php.net/note/delete/105179/in+docs
Del: other reasons-- https://master.php.net/note/delete/105179
Reject -- https://master.php.net/note/reject/105179
Search -- https://master.php.net/manage/user-notes.php