explode() into $key=>$value pair

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

    You can loop every second string:

    $how_many = count($array);
    for($i = 0; $i <= $how_many; $i = $i + 2){
      $key = $array[$i];
      $value = $array[$i+1];
      // store it here
    }
    

提交回复
热议问题