the => operator
Moderator: General Moderators
the => operator
I have a background in OOP, though not PHP.
I am getting back into this after a long time away.
Can someone point me towards an explanation of '=>' ?
It is proving difficult to search for. It may be something you need to understand in the larger sense.
Thanks.
J
I am getting back into this after a long time away.
Can someone point me towards an explanation of '=>' ?
It is proving difficult to search for. It may be something you need to understand in the larger sense.
Thanks.
J
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
It isn't an operator. It's a part of the inline array construct."bar" is the key that maps to "hi." It would be accessed through $foo['bar']
Code: Select all
$foo = array('bar' => 'hi');That makes sense.feyd wrote:It isn't an operator. It's a part of the inline array construct."bar" is the key that maps to "hi." It would be accessed through $foo['bar']Code: Select all
$foo = array('bar' => 'hi');
And does '::' refer to a parent's functions?
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Well, I'm probably not the best person to ask (what a way to start a reply!), but the only time I've seen/used that is when using a foreach loop.
Example:
Since you mentioned OOP in your post, I assume you mean '->' instead. This is used when handling a class.
Example:
Correct me if I'm wrong...
edit: got beaten to it.
Example:
Code: Select all
foreach (array_expression as $key => $value)
statementSince you mentioned OOP in your post, I assume you mean '->' instead. This is used when handling a class.
Example:
Code: Select all
class Something {
var $items;
function whatever() {
return $this->items; //that's how you would handle/access a variable set inside the class
}
}
$test = new Something;
$test->whatever(); //that's how you would call the whatever() function.edit: got beaten to it.
Last edited by jayshields on Mon Aug 14, 2006 11:50 am, edited 1 time in total.
Awesome.feyd wrote::: is the scope resolution operator, just like in C++. The left operand is either the name of a class or one of two special names: self and parent. The right operand is either a static property or static method of that class.
One more, please
'==='
Its not an equivalency check... thats '=='
You are not wrong. This is actually what I was asking. I confused myself.jayshields wrote:Well, I'm probably not the best person to ask (what a way to start a reply!), but the only time I've seen/used that is when using a foreach loop.
Example:Code: Select all
foreach (array_expression as $key => $value) statement
Since you mentioned OOP in your post, I assume you mean '->' instead. This is used when handling a class.
Example:Correct me if I'm wrong...Code: Select all
class Something { var $items; function whatever() { return $this->items; //that's how you would handle/access a variable set inside the class } } $test = new Something; $test->whatever(); //that's how you would call the whatever() function.
Thanks, J.
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Last edited by jayshields on Mon Aug 14, 2006 11:52 am, edited 1 time in total.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
triple equal (===) is an identity check. It not only checks the value to see that they are equal, but the types must match too.outputs
Code: Select all
var_dump(0 == '0', 0 === '0');Code: Select all
boolean(true)
boolean(false)One of my chick friends likes to refer to => as a "little rocket" 
how's that for a technical explaination?
=> is array assignment
-> is used in OOP
=== is used when you need to check types as well as value
how's that for a technical explaination?
=> is array assignment
Code: Select all
$array = (
'key1' => 'value1',
'key2' => 'value2'
);Code: Select all
$var = $object->doFunc($data);Code: Select all
$a = 0;
$b = '0';
if($a == $b)
{
//this will be true
}
if($a === $b)
{
// this will be false
}Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.