|
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/
Navigation:
[Reply to this message]
|