-2

So lets say I have an array and when I var_dump(); it, it has the following output:

[1]=>
string(20) "Name:          Kevin"
[2]=>
string(20) "Age:              20"

Can I manipulate it using implode or explode so that the output would look like this:

[Name]=>
string(5) "Kevin"
[Age]=>
string(2) "20"

Any help would be appreciated.

Tenka
  • 31
  • 6

1 Answers1

0

You can use explode() with trim()

$array = [];

foreach($initialArray as $data){
    $exploded = explode(':',$data);
    $array[trim($exploded[0])] = trim($exploded[1]);
}

Output:-https://3v4l.org/3q0i5

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98