Wednesday, 27 September 2017

What does "=>" mean in PHP?

Code like "a => b" means, for an associative array (some languages, like Perl, if I remember correctly, call those "hash"), that 'a' is a key, and 'b' a value.


You might want to take a look at the documentations of, at least:


Here, you are having an array, called $user_list, and you will iterate over it, getting, for each line, the key of the line in $user, and the corresponding value in $pass.


For instance, this code:


$user_list = array(
'user1' => 'password1',
'user2' => 'password2',
);
foreach ($user_list as $user => $pass)
{
var_dump("user = $user and password = $pass");
}

Will get you this output:


string 'user = user1 and password = password1' (length=37)
string 'user = user2 and password = password2' (length=37)

(I'm using var_dump to generate a nice output, that facilitates debuging; to get a normal output, you'd use echo)



"Equal or greater" is the other way arround: "greater or equals", which is written, in PHP, like this; ">="

The Same thing for most languages derived from C: C++, JAVA, PHP, ...



As a piece of advice: If you are just starting with PHP, you should definitely spend some time (maybe a couple of hours, maybe even half a day or even a whole day) going through some parts of the manual :-)

It'd help you much!

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...