我正在尝试从以下形式的数组中获取数据:
Array ( [actual-1] => 2 [action-1] => blabla [actual-2] => 1 [action-2] => sss [actual-49] => 3 [action-58] => sasa )
ID 1 Level 2 action blabla
ID 2 level 1 action sss
ID 49 level 3 action sasa
我尝试了以下代码:
foreach(array_chunk($array,3,true) as $val){
foreach($val as $k=>$v){
if(strpos($k, "actual") !== false){
$temp = explode("-",$k);
$id = $temp[1];
$actual = $v;
}
if(strpos($k, "action") !== false){
$action = $v;
}
}
echo "ID ".$id." Level ".$actual." action ".$action;
echo "<br>";
}
但我得到的是:
ID 2 Level 1 action blabla
ID 49 level 3 action sasa