Convert 1D Array to 2D Array and Join PHP

孤者浪人 提交于 2019-12-02 10:26:05

Try this

$array1 = array(
    'coupon_code' => 'GTY777R',
    'coupon_description' => 'Credito $5 USD',
);

$array2 = array(
    array(
        'coupon_code' => '0000000',
        'coupon_description' => 'Intenta de nuevo',
    ),
    array(
        'coupon_code' => '0000000',
        'coupon_description' => 'Intenta de nuevo',
    ),
);

$result = array();

# is 1D array
if (count($array1) == count($array1, COUNT_RECURSIVE))  {
    $result[] = $array1;    
}

# join it
$result = array_merge($result, $array2);

Results

Array
(
    [0] => Array
        (
            [coupon_code] => GTY777R
            [coupon_description] => Credito $5 USD
        )

    [1] => Array
        (
            [coupon_code] => 0000000
            [coupon_description] => Intenta de nuevo
        )

    [2] => Array
        (
            [coupon_code] => 0000000
            [coupon_description] => Intenta de nuevo
        )

)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!