Friday, October 4, 2019

php - What does $k => $v in foreach($ex as $k=>$v) mean?





Possible Duplicates:
What does “=>” mean in PHP?







What does $k => $v mean?


Answer



It means that for every key-value pair in the traversable variable $ex, the key gets assigned to $k and value to $v. In other words:



$ex = array("1" => "one","2" => "two", "3" => "three");
foreach($ex as $k=>$v) {
echo "$k : $v \n";
}



outputs:



1 : one
2 : two
3 : three

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...