gpt4 book ai didi

php - 在 PHP 中选择框数组

转载 作者:可可西里 更新时间:2023-10-31 22:58:08 27 4
gpt4 key购买 nike

好的,我正在尝试在选择每个数组后获取它们的循环...添加“语言”删除“语言”没问题。问题是提交。我被困在如何实际让每个选择框循环遍历 PHP 数组。

这是我的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />


<title>Untitled 5</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
$('#btnAdd').click(function() {
var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
var newNum = new Number(num + 1); // the numeric ID of the new input field being added

// create the new element via clone(), and manipulate it's ID using newNum value
var newElem = $('#input' + num).clone().attr('id', 'input' + newNum);

// manipulate the name/id values of the input inside the new element
newElem.children(':first').attr('id', 'name' + newNum).attr('name', 'name' + newNum);

// insert the new element after the last "duplicatable" input field
$('#input' + num).after(newElem);

// enable the "remove" button
$('#btnDel').removeAttr("disabled", "disabled");

// business rule: you can only add 5 names
if (newNum == 15)
$('#btnAdd').attr('disabled','disabled');
});

$('#btnDel').click(function() {
var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have

$('#input' + num).remove(); // remove the last element

// enable the "add" button
$('#btnAdd').removeAttr("disabled", "disabled");

// if only one element remains, disable the "remove" button
if (num-1 == 1)
$('#btnDel').attr('disabled','disabled');
});

//$('#btnDel').attr('disabled','disabled');
});
</script>
</head>
<body>
<?php
if ($_POST['submit']) {

$i = 0;
foreach ($_POST['langs'] as $value) {

echo "Langs $i: " . $_POST['langs'][$i];
$i++;

}
}
?>

<form id="myForm" action="lang.php" method="post">

<h1>Languages</h1>
<p>What languages do you know?</p>
<div>
<input type="button" id="btnAdd" value="add another name" />
<input type="button" id="btnDel" value="remove name" />
</div>
<div id="input1" style="margin-bottom:5px;" class="clonedInput">
<select name='langs[]' id="languages" size="1">
<option value='---'>Select Language</option>
<option value='AB'>Abkhazian</option>
<option value='AA'>Afar</option>
<option value='AF'>Afrikaans</option>
<option value='SQ'>Albanian</option>
<option value='AM'>Amharic</option>
<option value='AR'>Arabic</option>
<option value='HY'>Armenian</option>
<option value='AS'>Assamese</option>
<option value='AY'>Aymara</option>
<option value='AZ'>Azerbaijani</option>
<option value='BA'>Bashkir</option>
<option value='EU'>Basque</option>
<option value='BN'>Bengali</option>
<option value='DZ'>Bhutani</option>
<option value='BH'>Bihari</option>
<option value='BI'>Bislama</option>
<option value='BR'>Breton</option>
<option value='BG'>Bulgarian</option>
<option value='MY'>Burmese</option>
<option value='BE'>Byelorussian</option>
<option value='KM'>Cambodian</option>
<option value='CA'>Catalan</option>
<option value='ZH'>Chinese</option>
<option value='CO'>Corsican</option>
<option value='HR'>Croatian</option>
<option value='CS'>Czech</option>
<option value='DA'>Danish</option>
<option value='NL'>Dutch</option>
<option value='EN' selected="selected">English</option>
<option value='EO'>Esperanto</option>
<option value='ET'>Estonian</option>
<option value='FO'>Faeroese</option>
<option value='FJ'>Fiji</option>
<option value='FI'>Finnish</option>
<option value='FR'>French</option>
<option value='FY'>Frisian</option>
<option value='GL'>Galician</option>
<option value='KA'>Georgian</option>
<option value='DE'>German</option>
<option value='EL'>Greek</option>
<option value='KL'>Greenlandic</option>
<option value='GN'>Guarani</option>
<option value='GU'>Gujarati</option>
<option value='HA'>Hausa</option>
<option value='IW'>Hebrew</option>
<option value='HI'>Hindi</option>
<option value='HU'>Hungarian</option>
<option value='IS'>Icelandic</option>
<option value='IN'>Indonesian</option>
<option value='IA'>Interlingua</option>
<option value='IE'>Interlingue</option>
<option value='IK'>Inupiak</option>
<option value='GA'>Irish</option>
<option value='IT'>Italian</option>
<option value='JA'>Japanese</option>
<option value='JW'>Javanese</option>
<option value='KN'>Kannada</option>
<option value='KS'>Kashmiri</option>
<option value='KK'>Kazakh</option>
<option value='RW'>Kinyarwanda</option>
<option value='KY'>Kirghiz</option>
<option value='RN'>Kirundi</option>
<option value='KO'>Korean</option>
<option value='KU'>Kurdish</option>
<option value='LO'>Laothian</option>
<option value='LA'>Latin</option>
<option value='LV'>Latvian</option>
<option value='LN'>Lingala</option>
<option value='LT'>Lithuanian</option>
<option value='MK'>Macedonian</option>
<option value='MG'>Malagasy</option>
<option value='MS'>Malay</option>
<option value='ML'>Malayalam</option>
<option value='MT'>Maltese</option>
<option value='MI'>Maori</option>
<option value='MR'>Marathi</option>
<option value='MO'>Moldavian</option>
<option value='MN'>Mongolian</option>
<option value='NA'>Nauru</option>
<option value='NE'>Nepali</option>
<option value='NO'>Norwegian</option>
<option value='OC'>Occitan</option>
<option value='OR'>Oriya</option>
<option value='OM'>Oromo</option>
<option value='PS'>Pashto</option>
<option value='FA'>Persian</option>
<option value='PL'>Polish</option>
<option value='PT'>Portuguese</option>
<option value='PA'>Punjabi</option>
<option value='QU'>Quechua</option>
<option value='RM'>Rhaeto-Romance</option>
<option value='RO'>Romanian</option>
<option value='RU'>Russian</option>
<option value='SM'>Samoan</option>
<option value='SG'>Sangro</option>
<option value='SA'>Sanskrit</option>
<option value='GD'>Scottish Gaelic</option>
<option value='SR'>Serbian</option>
<option value='SH'>Serbo-Croatian</option>
<option value='ST'>Sesotho</option>
<option value='TN'>Setswana</option>
<option value='SN'>Shona</option>
<option value='SD'>Sindhi</option>
<option value='SI'>Singhalese</option>
<option value='SS'>Siswati</option>
<option value='SK'>Slovak</option>
<option value='SL'>Slovenian</option>
<option value='SO'>Somali</option>
<option value='ES'>Spanish</option>
<option value='SU'>Sudanese</option>
<option value='SW'>Swahili</option>
<option value='SV'>Swedish</option>
<option value='TL'>Tagalog</option>
<option value='TG'>Tajik</option>
<option value='TA'>Tamil</option>
<option value='TT'>Tatar</option>
<option value='TE'>Telugu</option>
<option value='TH'>Thai</option>
<option value='BO'>Tibetan</option>
<option value='TI'>Tigrinya</option>
<option value='TO'>Tonga</option>
<option value='TS'>Tsonga</option>
<option value='TR'>Turkish</option>
<option value='TK'>Turkmen</option>
<option value='TW'>Twi</option>
<option value='UK'>Ukrainian</option>
<option value='UR'>Urdu</option>
<option value='UZ'>Uzbek</option>
<option value='VI'>Vietnamese</option>
<option value='VO'>Volapuk</option>
<option value='CY'>Welsh</option>
<option value='WO'>Wolof</option>
<option value='XH'>Xhosa</option>
<option value='JI'>Yiddish</option>
<option value='YO'>Yoruba</option>
<option value='ZU'>Zulu</option>
</select> <select name='lang_level[]' id='lang_level' size="1">
<option value='---'>Select Language Level</option>
<option value='0'>Beginner</option>
<option value='1'>Intermediate</option>
<option value='2'>Advanced</option>
<option value='3'>Fluent</option>
<option value='4'>Native Speaker</option>
</select></div>
<br /><br />

<input type="submit" name="submit" value="Next step" />
</form>

</body>
</html>

最佳答案

你必须像这样使用foreach

foreach ($_POST['langs'] as $value) {

echo "Langs $i: " . $value;
$i++;

}

参见 here foreach 可以做什么。

关于php - 在 PHP 中选择框数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8395244/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com