note 76834 added to function.is-string

From: Date: Wed, 01 Aug 2007 15:44:18 +0000
Subject: note 76834 added to function.is-string
Groups: php.notes 
Request: Send a blank email to php-notes+get-129105@lists.php.net to get a copy of this message
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. ---- Server IP: 209.41.74.194 Probable Submitter: 216.58.233.82 ---- Manual Page -- http://www.php.net/manual/en/function.is-string.php Edit -- https://master.php.net/note/edit/76834 Del: integrated -- https://master.php.net/note/delete/76834/integrated Del: useless -- https://master.php.net/note/delete/76834/useless Del: bad code -- https://master.php.net/note/delete/76834/bad+code Del: spam -- https://master.php.net/note/delete/76834/spam Del: non-english -- https://master.php.net/note/delete/76834/non-english Del: in docs -- https://master.php.net/note/delete/76834/in+docs Del: other reasons-- https://master.php.net/note/delete/76834 Reject -- https://master.php.net/note/reject/76834 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129105) next »