explode() into $key=>$value pair

后端 未结 15 640
广开言路
广开言路 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:29

    $strVar = "key value";
    list($key, $val) = explode(' ', $strVar);
    
    $arr= array($key => $val);
    

    Edit: My mistake, used split instead of explode but:

    split() function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged

提交回复
热议问题