What do square brackets mean in the php manual?

藏色散人
Release: 2023-02-26 06:44:02
Original
4726 people have browsed it

What do square brackets mean in the php manual?

#What do the brackets mean in the php manual?

The square brackets in PHP are generally used to obtain the corresponding value of the array through the key name of the array. It is a symbol in PHP

For example:

<?php
$array = array(&#39;a&#39;,&#39;b&#39;);
echo $array[0];
//表单POST提交
$user = $_POST[&#39;user&#39;];
//表单GET提交
$user = $_GET[&#39;user&#39;];
//读取session
$user = $_SESSION[&#39;user&#39;];
//或者是可以通过空[]给数组赋值
$array[] = &#39;c&#39;;
print_r($array);
?>
Copy after login

Also in the form, add square brackets to the name of the element, and you can submit multiple elements with the same element name

For example:

<inpu type="text" name="user[]" value="1">
<inpu type="text" name="user[]" value="2">
<inpu type="text" name="user[]" value="3">
php处理时:
<?php
$user = $_POST[&#39;user&#39;];
//获取到一个数组形式的数据
print_r($user);
?>
Copy after login

For more PHP related knowledge, please visit PHP中文网!

The above is the detailed content of What do square brackets mean in the php manual?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!