0

hello everyone

Can someone explain to me about this two syntax of php the => and ->, i dont have any idea what this is. I already googled it but didnt find anythig. Actually I tried to look the source code of joomla and found this two syntax.

I will appreciate for any help. thanks.

4
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by ZER09
1

=>

is used for arrays, denoting key/value pairs eg.

$array = array('item1'=>'apple','item2'=>'pear');
foreach($array as $key=>$value){
    echo $key.' = '.$value;
}

->

is used for object orientated processing (OOP)

eg.

$shoppingcart = new basket();

$shoppingcart->addItem('apple');
$shoppingcart->displayBasket();
1

The first is found in arrays, assigning a value to a key

$myarray = array('name'=>'Ardav','country'=>'Wales');

The second is used in Object Orientated Programming for referencing variables and functions (or properties and methods as they are called in OOP-speak):

echo $myObj->name;
$country = $myObj->getCountry();

This last bit shouldn't be confused with the first bit of code (not related).

0

Thank you very much, as now i think i will research more about that.

BTW do you have a good totutrial or link for the OOP "->" w/o the quotes syntax and what is the name of this syntax, how do we call this syntax?

Edited by ZER09

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.