时间:2021-07-01 10:21:17 帮助过:10人阅读
$s = 'sex-1-area-2-pagesize-18-pageindex-1';Array
foreach(array_chunk(explode('-', $s), 2) as $v) {
$r[$v[0]] = $v[1];
}
print_r($r);
$s = 'sex-1-area-2-pagesize-18-pageindex-1';Array
preg_match_all('/(\w+)\-(\w+)/', $s, $r);
$r = array_combine($r[1], $r[2]);
print_r($r);
$test = "sex-1-area-2-pagesize-18-pageindex-1";
$preg = "/(?<=\d)-(?=[a-z])/";
$res = preg_split($preg,$test);
foreach($res as $tmp){
list($key,$value) = explode("-",$tmp);
echo $key."=>".$value;
}
$str = 'sex-1-area-2-pagesize-18-pageindex-1';
$str = explode('-', $str);
for($i=0,$max=count($str);$i<$max;$i++) {
$result[$str[$i]] = $str[++$i];
}
print_r($result);