Reply to Re: What is the difference between "=>" and "->" operators?

Your name:

Reply:


Posted by Toby A Inkster on 08/13/07 12:15

mejpark wrote:

> What is the difference between " => " and " -> " in PHP?

'=>' is used when filling an array to provide an explicit key for a value.
e.g.:

$team = array(
'Bob',
'Steve',
'Dave',
'manager'=>'Harry'
);

is roughly equivalent to:

$team = array();
$team[0] = 'Bob';
$team[1] = 'Steve';
$team[2] = 'Dave';
$team['manager'] = 'Harry';

'->' is an entirely different operator. It has nothing to do with arrays.
It it used to reference an object property or method in object-oriented
programming. It is equivalent to Java's "." operator. e.g.

$myCup = new Cup($cupsize);
echo $myCup->fill(LIQUIDS_ORANGE_JUICE, '300 mL');
if ($myCup->percentageFilled==100)
{
echo "Cup is full.\n";
if ($myCup->hasOverflowed)
echo "Cup has overflowed!\n";
}
else
{
echo "There's still room for vodka!\n";
}


--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 53 days, 15:46.]

PHP Debugging with Style -OR- How I Learned to Stop Worrying and Love the Bug
http://tobyinkster.co.uk/blog/2007/08/12/php-debugging-with-style/

[Back to original 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

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