>  기사  >  백엔드 개발  >  PHP는 동일한 이름을 가진 여러 값을 허용하고 이를 배열 형식으로 처리합니다.

PHP는 동일한 이름을 가진 여러 값을 허용하고 이를 배열 형식으로 처리합니다.

不言
不言원래의
2018-05-04 16:56:281555검색

이 글에서는 주로 PHP가 같은 이름을 가진 여러 값을 받아들이고 이를 배열 형식으로 처리하는 방법을 소개합니다. 이제 특정 참조 값이 있으므로 이를 참조할 수 있습니다.

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

관련 권장 사항:

PHP를 사용하여 파일을 허용하고 접미사 이름을 얻는 방법

PHP에서 허용하는 값의 글꼴 색상을 개별적으로 설정하는 방법


위 내용은 PHP는 동일한 이름을 가진 여러 값을 허용하고 이를 배열 형식으로 처리합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:PHP에서 쿠키 사용다음 기사:PHP에서 쿠키 사용