Home  >  Article  >  Backend Development  >  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

不言
不言Original
2018-05-04 16:56:281554browse

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

直接粘代码了,原谅我是一个懒散的人
<!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>
<?php 

	$values = $_POST["score"];

	var_dump($values)


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

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!

Statement:
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
Previous article:Use of Cookies in PHPNext article:Use of Cookies in PHP