|
Posted by David Haynes on 11/21/62 11:37
David Haynes wrote:
> Jim Michaels wrote:
>> I thought the syntax for PHP to access a string 's chars was $s{0} in
>> the manual.
>> does [0] really work in practice?
>> "Charlie King" <charlie@removethisitsaspamtrap.stopthatitssilly.com>
>> wrote in message news:2qdhs1l83afgqk9t5qnfhiffqt97oic9sd@4ax.com...
>>> On Sat, 07 Jan 2006 17:05:49 -0500, in
>>> <%WWvf.23054$%h2.16196@fe18.usenetserver.com> (alt.comp.lang.php)
>>> David Haynes <david.haynes2@sympatico.ca> wrote:
>>>
>>>
>>>> or
>>>> <?php
>>>> $s = "K123456";
>>>>
>>>> switch( $s[0] ) {
>>>> case 'K':
>>>> // code for K
>>>> break;
>>>> case 'T':
>>>> // code for T
>>>> break;
>>>> }
>>>> ?>
>>> or
>>>
>>> <?php
>>> $s = "K123456";
>>>
>>> switch( $s[0] ) {
>>> case 'K':
>>> // code for K
>>> break;
>>> case 'T':
>>> // code for T
>>> break;
>>>
>>> default:
>>> // code for when neither is true
>>>
>>> }
>>> ?>
>>>
>>> :)
>>> --
>>> Charlie
>>
>>
>
> Yes. $s[0] (which I read a 'ess at zero' works just fine.
Man! bad typing syndrome in action.
This should read:
$s[0] (which I read as 'string ess at zero') works just fine.
$s(0) does too, so does substr($s, 0, 1);
-david-
Navigation:
[Reply to this message]
|