explode() into $key=>$value pair

后端 未结 15 622
广开言路
广开言路 2020-12-01 09:24

I have this:

$strVar = \"key value\";

And I want to get it in this:

array(\'key\'=>\'value\')

I tried

15条回答
  •  独厮守ぢ
    2020-12-01 09:55

    Don't believe this is possible in a single operation, but this should do the trick:

    list($k, $v) = explode(' ', $strVal);
    $result[ $k ] = $v;
    

提交回复
热议问题