View Full Version : PHP: what is =>?
eldersoares
April 26th, 2007, 10:49 AM
hello
i've found in some codes this => but in the php docs it doesnt appear like an operator os smth like this... it seems to be somth related to arrays... but what is it exactly?!?!?!??!
thanks
jespdj
April 26th, 2007, 10:56 AM
You can find everything you want to know about PHP on: http://www.php.net
For an anwer to your question have a look at this: http://www.php.net/manual/en/language.types.array.php
eldersoares
April 26th, 2007, 11:01 AM
ok thanks
maddog39
April 27th, 2007, 12:25 AM
It defines the value of the second parameter in a 2D array. If that even makes sense. If you take a look at the foreach() control structure, you will see how this exactly works. Hard to explain really.
Compyx
April 28th, 2007, 09:06 AM
It defines the value of the second parameter in a 2D array. If that even makes sense. If you take a look at the foreach() control structure, you will see how this exactly works. Hard to explain really.
No, the => operator maps a key to a value in an array. In PHP these constructs are called associative arrays, in Perl they're called hashes.
This:
$MyArray = array (
"cpu" => "Athon XP",
"mem" => "1 GB",
"hdd" => "120 GB"
);
Generates a 1-dimensional associative array (a hash actually), in which a value can be looked up by a label, eg:
echo $MyArray["cpu"];
will print "Athlon XP".
All this is explained in great detail on the PHP website, as mentioned in an earlier post.
smartbei
April 29th, 2007, 04:12 PM
It is also used in:
$arr=array("x","y","z");
foreach($arr as $key => $val)
echo "$key $val<br>";
would print out:
0 x
1 y
2 z
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.