爆炸功能不在PHP中工作显示错误行需要参数2

时间:2016-06-03 11:38:45

标签: php codeigniter codeigniter-3 php-mysqlidb

这里是$_POST['members'],我想用|

分解它
[members] => Array
        (
            [0] => test.com|test Melissa
            [1] => eboo@abcd.com.au|Buckley test
            [2] => testtest@test.com.au|test Ashley
            [3] => testset.com.au|Forno test
            [4] => get.com.au|test Nathan
            [5] =>set.com.au|Brown test
        )

我正在尝试跟随PHP代码

$get=explode('|',$_POST['members']);
echo '<pre>'; 
print_r($get);

6 个答案:

答案 0 :(得分:1)

尝试类似

的内容
foreach($_POST['members'] as $str){
  $get[] = explode('|',$str);
}
print_r($get);

答案 1 :(得分:0)

由于$_POST['members']是数组,您需要通过访问所有数组元素在foreach中使用explode:

foreach($_POST['members'] as $members)
{
    $get=explode('|',$members);
    echo '<pre>'; print_r($get);
}

答案 2 :(得分:0)

循环通过数据阵列,将爆炸的结果存储在一个新阵列中,也许你得到了你想要的东西:

<?php
    $arr                    = [
        0 => "test.com|test Melissa",
        1 => "eboo@abcd.com.au|Buckley test",
        2 => "testtest@test.com.au|test Ashley",
        3 => "testset.com.au|Forno test",
        4 => "get.com.au|test Nathan",
        5 => "set.com.au|Brown test"
    ];

        $arrSubData         = array();
        foreach($arr as $pipeDividedString){
            $arrSubData[]   = explode('|', $pipeDividedString);
        }


        var_dump($arrSubData);

<强>转储

    array (size=6)
          0 => 
            array (size=2)
              0 => string 'test.com' (length=8)
              1 => string 'test Melissa' (length=12)
          1 => 
            array (size=2)
              0 => string 'eboo@abcd.com.au' (length=16)
              1 => string 'Buckley test' (length=12)
          2 => 
            array (size=2)
              0 => string 'testtest@test.com.au' (length=20)
              1 => string 'test Ashley' (length=11)
          3 => 
            array (size=2)
              0 => string 'testset.com.au' (length=14)
              1 => string 'Forno test' (length=10)
          4 => 
            array (size=2)
              0 => string 'get.com.au' (length=10)
              1 => string 'test Nathan' (length=11)
          5 => 
            array (size=2)
              0 => string 'set.com.au' (length=10)
              1 => string 'Brown test' (length=10)

答案 3 :(得分:0)

$_POST['members']是一个数组,explode();适用于字符串。您必须遍历数组并爆炸每个值。像这样:

$arr = array(
  'test.com|test Melissa',
  'eboo@abcd.com.au|Buckley test',
  'testtest@test.com.au|test Ashley',
  'testset.com.au|Forno test',
  'get.com.au|test Nathan',
  'set.com.au|Brown test'
);
$get = array();
foreach ($_POST['members'] as $member) {
  $get[] = explode('|',$member);
}
echo '<pre>'; print_r($get);

答案 4 :(得分:0)

为了explode您需要循环播放$_POST['members']的值,您可以使用foreach()
以下是使用explode()list()的示例:

<?php
$members = !empty($_POST['members']) ? $_POST['members'] : die("post members is empty");
foreach($members as $member)
{
    list($siteEmail, $name) = explode("|", $member);
    echo "<pre> $siteEmail $name </pre>";
}

http://ideone.com/qdDmSe

答案 5 :(得分:0)

你可以这样使用

foreach($_POST['members'] as $val){ $get = explode('|',$val);
} echo "<pre>";print_r($get);