gpt4 book ai didi

php - 没有获得正确的多个数组值

转载 作者:行者123 更新时间:2023-11-29 11:54:08 25 4
gpt4 key购买 nike


我正在做一个项目。在该项目中,我在多个数组中遇到一些问题。
这个 (categ[0][category],categ[1][category],categ[2][category]) 是动态的.仅供引用,我正在做静态..选择选项是多个

<select multiple name="categ[0][category]">
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
</select>
<select multiple name="categ[1][category]">
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
</select>
<select multiple name="categ[2][category]">
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
</select>

After POST,It shows only last value.(eg.)If I select 2,3,4 in categ[0][category] and 1,3,4 in categ[1][category] and 2,3 in categ[2][category] .It display only 4,4,3 these are selected last values.

this is my php code..

           $categ=array();$categ=$_POST['categ'];
foreach ($categ as $row)
{

$ddd=array();echo $ddd=$row['category'];
foreach($ddd as $ds)
{
foreach($ds as $fdfd)
{
echo implode(",",$fdfd);
}
}
}

最佳答案

删除代码中的一个 foreach

$categ = array();
$categ = $_POST['categ'];
foreach ($categ as $row) {

$ddd = array();
echo $ddd = $row['category'];
foreach ($ddd as $ds) {
echo implode(",", $ds);
}
}

关于php - 没有获得正确的多个数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33497146/

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