note 26537 deleted from language.types.string by googleguy

From: Date: Wed, 16 Jan 2013 05:26:10 +0000
Subject: note 26537 deleted from language.types.string by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193087@lists.php.net to get a copy of this message
Note Submitter: vallo at cs dot helsinki dot fi ---- Even if the correct way to handle variables is determined from the context, some things just doesn't work without doing some preparation. I spent several hours figuring out why I couldn't index a character out of a string after doing some math with it just before. The reason was that PHP thought the string was an integer! $reference = $base + $userid; .. looping commands .. $chartohandle = $reference{$last_char - $i}; Above doesn't work. Reason: last operation with $reference is to store a product of an addition -> integer variable. $reference .=""; (string catenation) had to be added before I got it to work: $reference = $base + $userid; $reference .= ""; .. looping commands .. $chartohandle = $reference{$last_char - $i}; Et voilá! Nice stream of single characters.

« previous php.notes (#193087) next »