在这个例子中,我使用delete []数组提交一个数组数组,这个数组得到正确的处理,我也想提交数组条件[]这个没有得到正确的处理,最好的方法是解决这个问题?
$catalog = $database->getInventory(); if($catalog){ $numRows = sizeof($catalog);//count echo "<b>Book Count:</b> ".$numRows."<br>"; echo "<form method='post' action='inventory.PHP'>"; echo "<table id='example' class='tablesorter' border='0' cellpadding='0' cellspacing='1'>"; echo " <thead> <tr> <th>ISBN</th> <th>Title </th> <th>Rank </th> <th>Condition </th> <th><input type='checkBox' name='delete' value='all' /></th> </tr> </thead>\n"; foreach($catalog as $elem){ echo " <tr> <td>".$elem["isbn"]."</td> <td>".$elem["title"]."</td> <td>".$elem["rank"]."</td> <td>".$elem["condition"]."</td> <td> <input type='checkBox' name='add[]' value='".$elem['isbn']."_".$elem['condition']."_"."' /> </td> </tr>"; } echo "</table>"; echo "</form>"; }
示例html标记
<form method='post' action='inventory.PHP'> <table> <tr> <td> <input type='hidden' name='addInventoryBook' value='1'> <input type='submit' value='Add' /> </td> </tr> <tr> <td> <input type='checkBox' name='add[]' value='100001_used' /> </td> </tr> <tr> <td> <input type='checkBox' name='add[]' value='100001_new' /> </td> </tr> <tr> <td> <input type='checkBox' name='add[]' value='100003_new' /> </td> </tr> </table> </form>
function Inventory(){ if(isset($_POST['addInventoryBook'])){ if(isset($_POST['add']) && is_array($_POST['add'])){ $arr = array(); foreach($_POST['add'] as $checkBox){ $temp = explode("_",$checkBox); $arr[] = array( "isbn" => $temp[0],"condition" => $temp[1],"sub_condition" => $temp[2] ); } $this->addInventoryBook($arr); } else{ echo "No values have been set"; } } function addInventoryBook($arr){ foreach($arr as $elem){ //if used get sub-category if($elem['condition']=='used'){ echo $elem['isbn']."-".ucfirst($elem['condition']) .ucfirst($elem['sub_condition'])."<br>"; } else if($elem['condition']=='new'){ echo $elem['isbn']."-".ucfirst($elem['condition'])."<br>"; } } }
所有我想要的是基本上能够通过两个数组到我的PHP脚本
当前输出
100001 100002 100003
所需输出
100001 good 100002 new 100003 new