" symbol is very common in PHP scripts, so what is the use of the "=>" symbol? The following article will introduce you to the "=>" symbol and briefly introduce how to use the "=>" symbol. I hope it will be helpful to you.">
The "=>" symbol is very common in PHP scripts, so what is the use of the "=>" symbol? The following article will introduce you to the "=>" symbol and briefly introduce how to use the "=>" symbol. I hope it will be helpful to everyone.
PHP's "=>" symbol
In PHP"=> The ;" symbol is used to allocate key-value pairs in an array, mainly used in associative arrays. [Video tutorial recommendation:PHP tutorial]
Basic sentence structure:
key => value
Explanation: The value on the left side of the "=>" symbol is called the key, and the value on the right side is called key value.
Examples of using the "=>" symbol
The following is a simple code example to introduce how to use the "=>" symbol.
Example 1: Create an associative array using "=>" notation
95, "Physics" => 90, "Chemistry" => 96, "English" => 93, "Computer" => 98 ); echo "学生成绩:
"; echo "数学:" . $subject["Maths"], "
"; echo "物理:" . $subject["Physics"], "
"; echo "化学:" . $subject["Chemistry"], "
"; echo "英语:" . $subject["English"], "
"; echo "计算机:" . $subject["Computer"], "
"; ?>
Output:
' symbol in PHP? (code example)" > symbol in PHP? (code example)" title="155133715739596What is the use of the => symbol in PHP? (code example)" alt="What is the use of the => symbol in PHP? (code example)"/>
Example 2: Create a numeric index array using the "=>" notation
7, "1" => 10, "2" => 8, "3" => 5 ); foreach($arr as $key => $value) { echo $key . " => " . $value . "
"; } ?>
Output:
Example 3: Use For assigning numeric indexes without using the "=>" symbol
$value) { echo $key . " => " . $value . "
"; } ?>
Output:
[Related article recommendations]
What is the use of the $$ symbol in PHP? how to use? (code example)
#How to use the double NOT (!!) operator in PHP? (Code example)
What is the use of the short opening tag "=" in PHP?
The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !
The above is the detailed content of What is the use of the '=>' symbol in PHP? (code example). For more information, please follow other related articles on the PHP Chinese website!