弹出第一个元素数组,在php代码点火器中插入批处理


Pop first element array to insert batch in php codeigniter

我有一个基于我的帖子表单的数组:

Array
(
[condition] => Array
    (
        [0] => 1
        [1] => 2
        [2] => 3
    )
[container] => Test
[status_clean] => Yes
[owner] => Yes
[last_cargo] => 9
[vessel] => Saja
[insulation] => 2
[tare] => Yup
[gross] => Test
[capacity] => Saja
[date_of_manu] => Yeah
[name_manu] => Clip
[last25] => Converter
[cert25] => Yeah
[last5] => Saja
[cert5] => 
[list3_item_0] => 2
[list3_kondisi_0] => OK
[comments] => Test Comments
)

如何弹出数组的第一个元素?我使用

$cond = array_keys($this->input->post()) ;
    echo "<pre>";
    print_r(array_shift($cond));

它只给我condition。我想把第一个元素数组弹出到insert_batch,剩下的像容器一样的status_clean将插入到另一个表中。任何hlep都非常感谢。

试试这个

$cond = array_keys($this->input->post()) ;
$first=array_shift($cond);
echo "<pre>";
print_r($cond);

试试这个:

<?php
$cond = array('condition' => array(0 => 1, 1 => 2, 2 =>3),
              'container' => 'Test',
              'status_clean' => 'Yes',
              'owner' => 'Yes',
              'last_cargo' => 9,
              'vessel' => 'Saja',
              'insulation' => 2,
              'tare' => 'Yup',
              'gross' => 'Test',
              'capacity' => 'Saja',
              'date_of_manu' => 'Yeah',
              'name_manu' => 'Clip',
              'last25' => 'Converter',
              'cert25' => 'Yeah',
              'last5' => 'Saja',
              'cert5' => '',
              'list3_item_0' => 2,
              'list3_kondisi_0' => 'OK',
              'comments' => 'Test Comments');
// first get the `condition`'s value
$condition_arr = array_shift($cond);
echo "<pre>";
print_r($condition_arr); // condition values
print_r($cond);      // all without condition
echo "</pre>";
?> 

输出。第一个数组是condition,第二个数组是数组的其余部分:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)

Array
(
    [container] => Test
    [status_clean] => Yes
    [owner] => Yes
    [last_cargo] => 9
    [vessel] => Saja
    [insulation] => 2
    [tare] => Yup
    [gross] => Test
    [capacity] => Saja
    [date_of_manu] => Yeah
    [name_manu] => Clip
    [last25] => Converter
    [cert25] => Yeah
    [last5] => Saja
    [cert5] => 
    [list3_item_0] => 2
    [list3_kondisi_0] => OK
    [comments] => Test Comments
)

您必须使用

foreach($array as $val)
   {
     foreach($val['condition'] as $value)
        {
          echo $val;
        }
}