Home > Backend Development > PHP Tutorial > PHP accepts multiple values ​​with the same name and processes them in the form of arrays

PHP accepts multiple values ​​with the same name and processes them in the form of arrays

不言
Release: 2023-03-25 12:14:01
Original
1636 people have browsed it

This article mainly introduces how PHP accepts multiple values ​​with the same name and processes them in the form of an array. It has a certain reference value. Now I share it with you. Friends in need can refer to it

直接粘代码了,原谅我是一个懒散的人
Copy after login
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>55 Array</title>
	<style type="text/css">
		.inputList{
			width: 80%;
			min-height: 400px;
			margin: 10px auto;
			border: 1px solid #333333;
		}
		.listItem{
			text-align: center;
			margin: 10px auto;
			border-bottom: 1px dashed #666666;
			padding-bottom: 4px;
		}
		.add,i{
			display:block;
			font-style: normal;
			width: 20px;
			height: 20px;
			line-height: 20px;
			text-align: center;
			border: 2px solid darkorange;
			border-radius: 15px;
			margin: 10px auto;
			color: darkorange;
			cursor: pointer;
		}
		.listInput{
			margin-left: 20px;
			border: 0.25px solid #333333;
			height: 20px;
			line-height: 20px;
		}
		.sub{
			display:block;
			margin: 10px auto;
		}
	</style>
</head>
<body>
	<form action="55homework.php" method="post">
		<p class="inputList">
			<p class="listItem">
				<label for="score">输入学生的比赛成绩:</label>
				<input type="text" name="score[]" id="score" class="listInput" autofocus="true">
			</p>
			<i class="add">+</i>
		</p>
		<input type="submit" name="" value="输入完毕开始提交" class="sub">
	</form>


	<script type="text/javascript">
		!(function(window,undefined){
			var oPlus = document.getElementsByClassName("add")[0];
			var oList = document.getElementsByClassName("inputList")[0];

			oPlus.addEventListener(&#39;click&#39;,function(){
				var newItem = document.createElement("p");
				newItem.classList="listItem";
				var str = &#39;<label for="score">输入学生的比赛成绩:</label><input type="text" name="score[]" id="score" class="listInput" autofocus="true">&#39;;
				newItem.innerHTML = str;
				oList.insertBefore(newItem,oList.lastElementChild);
				//console.dir(oList.lastElementChild);
			});

		})(window,undefined);

	</script>
</body>
</html>
Copy after login
<?php 

	$values = $_POST["score"];

	var_dump($values)


 ?>
Copy after login
array(2) { [0]=> string(2) "22" [1]=> string(2) "23" }
Copy after login

Related recommendations:

How to use PHP to accept files and obtain their suffix names

How to individually set the font of the value accepted by PHP color


The above is the detailed content of PHP accepts multiple values ​​with the same name and processes them in the form of arrays. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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