phparrayssplitassociative-array

Split a delimited string into a key-value pair


How do I implode 2 values, 1 as the key and the other as the value. Say I have:

$string = 'hello_world';

$arg = explode('_', $string);

I now have $arg[0] and $arg[1] (as you know)

How can I implode that so it becomes this structure

Array (
    'hello' => 'world'
)

Solution

  • $array = array($arg[0] => $arg[1]);