Friday 4 October 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...