Question User Question User - 2 months ago 8
PHP Question

add the key name and value for the same array in php

I have some array like this how can i split the key and value in php ?

[A0E4NL014XVM273] => Array
(
[0] => qexixdb
)

[A0E4UK024XVM014_Clone] => Array
(
[0] => pe8w3100
[1] => pe8w3100
)


Tried Query

foreach($vm_array as $vmkey=> $vmvalue){
$varray[] = $vmvalue;
/*foreach($vmvalue as $vmvalue=> $vmvalufmarray){
$vm_array[$vmkey][] = $vmvalufmarray.',';
}*/
}


Expected Output

[A0E4UK024XVM014_Clone] => pe8w3100,pe8w3100

Answer

You need to make a function called implode().

foreach($vm_array  as $vmkey=> $vmvalue){
    $varray[$vmkey] = implode(",", $vmvalue);
}
print_r($varray);
Comments