note 76834 deleted from function.is-string by danbrown
| From: | danbrown@php.net | Date: | Mon, 01 Nov 2010 14:09:06 +0000 |
| Subject: | note 76834 deleted from function.is-string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173652@lists.php.net to get a copy of this message | ||
Note Submitter: Dainix Zsigmond
----
To php dot net at oui dot jp:
It's going to return a string if the variable's value is encased around quotes or
apostrophes, period. Be it a '0' or a '1', it's a string all around. The
index in an array is a little bit of a different story.
Sample coding is below:
<?php
$ar = array('this is a string.', '38', '038', 0382, 3892.283);
$ar2 = array('S1' => 'string.', 'S2' => 'a string.',
'3' => 3827, '3.82.' => '2222', '-1' =>
'foo');
foreach($ar as $num => $string)
{
if (is_string($string)) { echo 'Yes. <br />'; } else { echo 'No. <br
/>'; }
}
print_r($ar);
foreach($ar2 as $num => $string)
{
if (is_string($num)) { echo 'Yes. <br />'; } else { echo 'No. <br
/>'; }
}
print_r($ar2);
?>
The first foreach contains a simple if/then statement that checks if the array value is a string or
not, which works correctly (Yes, Yes, Yes, No, No). The second checks if the index identifier is a
string. It returns Yes, Yes, No, and Yes.
Printing the array: Array ( [S1] => string. [S2] => a string. [3] => 3827 [3.82] => 2222
[-1] => foo)
The index identifier will be marked as a string if the identifier is not an integer above zero.