Could someone explain to me the difference between using => or ->? Is there any logical difference? Thanks!
            Asked
            
        
        
            Active
            
        
            Viewed 49 times
        
    -2
            
            
        - 
                    If you can add into your question the case where you thought the two symbols might be interchangeable, that might make for a unique question. I should be interested to that code in any case. – halfer Jan 19 '14 at 19:49
1 Answers
4
            
            
        => is used when defining arrays, and also in foreach loops that use keys, e.g.
$foo = array('bar' => 'baz');
foreach ($array as $key => $value) {...}
-> is used to refer to object members, e.g.
$obj->method();
$obj->property;
They are never interchangeable.
 
    
    
        George Brighton
        
- 5,131
- 9
- 27
- 36
- 
                    
- 
                    @AbhiBeckert added `foreach` example. AFAIK they are the only two uses... – George Brighton Jan 19 '14 at 19:15
- 
                    
- 
                    @DamienPirsy checke the language specification, I'm aware of at least 4 of them, but there are probably more. – Abhi Beckert Jan 19 '14 at 19:39
- 
                    @Abhi, I should be interested too what the other uses are - you've got me curious! – halfer Jan 19 '14 at 19:47
- 
                    @AbhiBeckert Nope, I'm trying but can't find the other 2 uses (besides arrays and foreach) you're talking about. Please stop being mysterious and tell us! :) – Damien Pirsy Jan 19 '14 at 19:51
