在foreach循环中构建正确的数组

时间:2016-10-05 11:58:03

标签: php arrays

我正在构建一个具有虚拟数据的API(Yay)。 数组是非常基本的,但我卡住了。 api会完美地吃掉虚拟数据,但不是我动态制作的数据。

这是虚拟阵列:

   array(
        'Name'=> 'Testing Recipient1',
        'Email'=> 'test@test.no',
        'MobileNumber'=> '32323232',
        // 'SSN'=> '00000000000',
        'Priority'=> 0
  ),
    array(
        'Name'=> 'Test Test',
        'Email'=> 'Test@test2.no',
        'MobileNumber'=> '32323232',
        // 'SSN'=> '00000000000',
        'Priority'=> 0
    )
);

所以我就这样做了:

$recipients2 = array();
foreach($signants as $signant) {
    $name = $signant['signame'];
    $email = $signant['signmail'];
    $signarr = array(
        "Name" => $name,
        "Email" => $email,
        "MobileNumber" =>'32323232',
        "Priority"=>'0'
    );
    array_push($recipients2, $signarr);
}

输出是:

 Array
(
    [0] => Array
        (
            [Name] => test test
            [Email] => test@test2.no
            [MobileNumber] => 32323232
            [Priority] => 0
        )

    [1] => Array
        (
            [Name] => test test
            [Email] => test@gmail.com
            [MobileNumber] => 32323232
            [Priority] => 0
        )

)

在NULLS名称中,我做错了什么?

0 个答案:

没有答案