|
Posted by Kimmo Laine on 11/29/06 08:58
"Thomas Mlynarczyk" <thomas@mlynarczyk-webdesign.de> wrote in message
news:eki6p7$5sp$03$1@news.t-online.com...
> Also sprach BKDotCom:
>
>> sam wrote:
>>> What is the meaning of this operator:-
>>> =>
>
>> Assignment - used in arrays?
>
> Hm. But why the need for a special operator here? Wouldn't a simple = have
> done the job just as well?
concider the syntax in that case:
$foo = 'bar';
$array1 = array($foo => 'zap');
$array2 = array($foo = 'zap');
In the first case you'll get
$array1['bar'] = 'zap'
$foo = 'bar'
but in the second case
$array2[0] = 'zap'
$foo = 'zap'
The results are very different and the reason is clear, the = operator means
a completely different thing than => operator. To get the effect what you
want you need to have another operator. How is php going to know which one
you meant?
And remember it's used in foreach as well:
foreach($array as $key => $val) vs. foreach($array as $key = $val)
Again, very different results, I guess both would be still valid syntax,
although I'm not quite sure about the latter.
The operations that the operators perform are clearly different, that is why
there is a need for two different operators as well.
--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti pδivittyvδ nettisarjis
spam@outolempi.net | rot13(xvzzb@bhgbyrzcv.arg)
Navigation:
[Reply to this message]
|