将多维数组转换为单维数组


Convert a Multidimensional array to single Dimension

这是我目前拥有的数组,请将其转换为下面的单维数组:-

Array
(
    [0] => Array
        (
            [is_custom] => yes
        )
    [1] => Array
        (
            [custom_amount] => 45
        )
    [2] => Array
        (
            [custom_amount_text] => Enter Amount
        )
    [3] => Array
        (
            [amount_btn] => Dropdown
        )
    [4] => Array
        (
            [multiple_amounts] => W3sidGl0bGUiOiJMYWJlbCIsImFtb3VudCI6IjQ1In0seyJ0aXRsZSI6IkxhYmVsIiwiYW1vdW50IjoiNDU1In1d
        )
    [5] => Array
        (
            [recurring_plans] => W3sibmFtZSI6IkxhYmVsIiwicmVjdXJyaW5nX2Ftb3VudCI6Ijc4In0seyJuYW1lIjoidSIsInJlY3VycmluZ19hbW91bnQiOiI3ODgifV0=
        )
    [6] => Array
        (
            [recurring_interval] => WyJNb250aGx5IiwiUXVhcnRlcmx5IiwiSGFsZi1ZZWFybHkiXQ==
        )
    [7] => Array
        (
            [admin_mail_subject] => 
        )
    [8] => Array
        (
            [admin_mail_body] => 
        )
    [9] => Array
        (
            [user_mail_subject] => 
        )
    [10] => Array
        (
            [user_mail_body] => 
        )
    [11] => Array
        (
            [is_recurrance] => yes
        )
    [12] => Array
        (
            [is_onetime] => yes
        )
)

现在我想把它转换成这样的格式

Array([0]=> 
[is_custom] => yes 
[custom_amount] => 45 
[custom_amount_text] => Enter Amount 
[amount_btn] => Dropdown 
[multiple_amounts] => W3sidGl0bGUiOiJMYWJlbCIsImFtb3VudCI6IjQ1In0seyJ0aXRsZSI6IkxhYmVsIiwiYW1vdW50IjoiNDU1In1d
[recurring_plans] => W3sibmFtZSI6IkxhYmVsIiwicmVjdXJyaW5nX2Ftb3VudCI6Ijc4In0seyJuYW1lIjoidSIsInJlY3VycmluZ19hbW91bnQiOiI3ODgifV0=
)

数组0键将有所有的键可以,这是可能的。我试过了,但失败了。请给我一个可能的解决方案

使用RecursiveIteratorIterator快速和简单。

$output_array = iterator_to_array(new RecursiveIteratorIterator(new RecursiveArrayIterator($input_array)), 0); //$input_array-Replace your arrray
echo "<pre>";
print_r($output_array);
echo "</pre>";
结果:

Array
(
    [0] => yes
    [1] => 45
    [2] => Enter Amount
    [3] => Dropdown
    [4] => W3sidGl0bGUiOiJMYWJlbCIsImFtb3VudCI6IjQ1In0seyJ0aXRsZSI6IkxhYmVsIiwiYW1vdW50IjoiNDU1In1d
    [5] => W3sibmFtZSI6IkxhYmVsIiwicmVjdXJyaW5nX2Ftb3VudCI6Ijc4In0seyJuYW1lIjoidSIsInJlY3VycmluZ19hbW91bnQiOiI3ODgifV0=
    [6] => WyJNb250aGx5IiwiUXVhcnRlcmx5IiwiSGFsZi1ZZWFybHkiXQ==
    [7] => 
    [8] => 
    [9] => 
    [10] => 
    [11] => yes
    [12] => yes
)

运行自己:

http://sandbox.onlinephpfunctions.com/code/86a50fd58455d64c4de074b888d5d2ea5ee1dd13

试试这个

$newArray=array_map(function($v){
return current($v);
},$oldArray);