$str = 'step=5
min=0
max=100';
$output = array();
$array = explode("\n",$str);
foreach($array as $a){
$output[substr($a,0,strpos($a,"="))] = substr($a,strpos($a,"=")+1);
}
echo '<pre>';
print_r($output);
echo '</pre>';
或者:
$str = 'step=5
min=0
max=100';
$output = array();
preg_match_all("/(.*)=(.*)/",$str,$matches);
if(isset($matches[1]) && isset($matches[2])){
foreach($matches[1] as $k=>$m){
$output[$m] = $matches[2][$k];
}
}
echo '<pre>';
print_r($output);
echo '</pre>';
或基于评论:
$str = 'step=5
min=0
max=100';
$output = array();
preg_match_all("/(.*)=(.*)/",$str,$matches);
if(isset($matches[1],$matches[2])){
$output = array_combine($matches[1],$matches[2]);
}
echo '<pre>';
print_r($output);
echo '</pre>';