如何在php中将文本框值添加到userarray

时间:2011-07-27 05:39:22

标签: php codeigniter

我得到了n个文本框值,我可以通过变量获取它...我的问题是我有一个数组,源代码如下所示

 for ($x = 1; $x <= $num; $x++) {

     $userArray[] = $this->input->post("select" . $x . "");
     $quantity = $this->input->post('Quantity'.$x);
     $quantity = $quantity.(" "); 
     echo $quantity;

数量输出为12345 000000 12345

    }
    if (is_array($userArray) && !empty($userArray))
 {
foreach ($userArray as $user)
{
  $row = explode(',', $user);
  echo implode(",",$row);
 // print_r($row);
  $productName = (isset($row[0]) ? $row[0] : '');
 // print_r($productName);

输出3合1包装棒JAI GANESH,3合1包装棒JAI GANESH,3合1包装棒JAI GANESH,

  $barcode = (isset($row[1]) ? $row[1] : '');
 // print_r($barcode);  

OUTPUT 683988 683988 683988

  $quantity = $this->input->post("Quantity" . $x . "");
 // print_r($quantity); 

此处产生的问题就像数量1数量1数量1

     $flag = $this->cartmodel->productCategory($category);
    // print_r($flag);
  }
  }

我需要在用户数组中添加数量的输出..如何实现这一点..感谢您的时间

最终输出应为

3 IN 1 INCENSE STICKS JAI GANESH 683988 12345

3 IN 1 INCENSE STICKS JAI GANESH 683988 000000 

3 IN 1 INCENSE STICKS JAI GANESH 683988 12345

1 个答案:

答案 0 :(得分:0)

也许:

for ($x = 1; $x <= $num; $x++) {
    $userArray[] = $this->input->post("select" . $x . "");
    //$quantity = $this->input->post('Quantity' . $x);
    //$quantity = $quantity . (" ");
    //echo $quantity;
    //output of quantity is 12345 000000 12345
    if (is_array($userArray) && !empty($userArray)) {
        foreach ($userArray as $user) {
            $row = explode(',', $user);
            echo implode(",", $row);
            // print_r($row);
            $productName = (isset($row[0]) ? $row[0] : '');
            // print_r($productName);
            //OUTPUT 3 IN 1 INCENSE STICKS JAI GANESH,3 IN 1 INCENSE STICKS JAI GANESH,3 IN 1 INCENSE STICKS JAI GANESH,

            $barcode = (isset($row[1]) ? $row[1] : '');
            // print_r($barcode);
            //OUTPUT 683988 683988 683988

            $quantity = $this->input->post("Quantity" . $x . "");
            // print_r($quantity);
            //THE PROBLEM ARISES HERE OUTPUT COMES LIKE Quantity1 Quantity1 Quantity1

            $flag = $this->cartmodel->productCategory($category);
            // print_r($flag);
        }
    }
}