You are here: Re: Arrays: $SomeArray{0} vs. $SomeArray[0] « PHP Programming Language « IT news, forums, messages
Re: Arrays: $SomeArray{0} vs. $SomeArray[0]

Posted by Norman Peelman on 12/01/06 12:48

"Ira Gladnick" <IraGladnick@yahoo.com> wrote in message
news:1164951377.341133.224300@n67g2000cwd.googlegroups.com...
> I have found that in PHP 5, <?php $SomeArray{0} = $somevalue ?> (note
> the squigly braces) appears to be functionally equivalent to the more
> usual <?php $SomeArray[0] = $somevalue ?> (square array brackets).
>
> However, doing $SomeArray{} = $somevalue raises an error.
>
> I can't seem to find any documentation that indicates why you can use
> squigly braces in the case where an array index is provided. Was
> wondering if someone could explain why they work in that situation, and
> possibly provide a reference to this use of squigly braces in the PHP 5
> documentation.
>
> (I am a rank PHP newbie, for whatever that's worth..)
>

You use [ ] on arrays such as:

$someArray[0] = "0123456789";
$someArray[1] = "rock 'n roll";

echo $someArray[0] will output:
0123456789

echo $someArray[1] will output:
rock 'n roll

You use { } on strings such as:

$someString1 = "0123456789";
$someString2 = "rock 'n roll";

echo $someString1{5} will output:
5

echo $someString2{3} will output:
k

strings are zero based... with this method you can manipulate strings at the
character level if you want.

Norm
--
FREE Avatar hosting at www.easyavatar.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация