从包含关键字的数组中提取值,这些关键字和值由任何符号(如,)分隔,


extract values from an array that contain key and values separated by any symbol like ,

我有一个数组,如下所示,所有值都是动态生成的

array(      
[education_provider_state]=>Arunanchal Pradesh,Assam        
[e_p_coeducational_type]=>Co-Ed,Girls       
)

我想要像一样的输出

array(      
[education_provider_state]=>array([0]=>Arunanchal Pradesh[1]=>Assam         
[e_p_coeducational_type]=>array([0]=>Co-Ed[1]=>Girls        
)

我想得到键的值和相应键的值。我怎样才能做到这一点请有人帮帮我。谢谢

只需将array_mapexplode一起用作

print_R(array_map(function($v){ return explode(',',$v);},$arr));

输出:

Array
(
    [education_provider_state] => Array
        (
            [0] => Arunanchal Pradesh
            [1] => Assam
        )
    [e_p_coeducational_type] => Array
        (
            [0] => Co-Ed
            [1] => Girls
        )
)

演示

foreach($array as $key=>$value) {
   echo "This is my $key and this is my $value'n";
}