我有这个$ record数组
array(4) {
[0]=> array(2) { ["ROLE_ID"]=> string(1) "2" ["SUBFUNCTION_ID"]=> string(3) "904" }
[1]=> array(2) { ["ROLE_ID"]=> string(1) "2" ["SUBFUNCTION_ID"]=> string(3) "903" }
[2]=> array(2) { ["ROLE_ID"]=> string(1) "2" ["SUBFUNCTION_ID"]=> string(3) "902" }
[3]=> array(2) { ["ROLE_ID"]=> string(1) "2" ["SUBFUNCTION_ID"]=> string(3) "901" }
}
我如何操纵它以便它会变成这样?
array("901","902","903","904");
提前致谢
答案 0 :(得分:5)
$subfunctionIds = array();
foreach($record as $values) {
$subFunctionIds[] = $values['SUBFUNCTION_ID'];
}
// If you want them reversed like in your example output...
$subFunctionIds = array_reverse($subFunctionIds);
var_dump($subFunctionIds);
答案 1 :(得分:2)
function fetch($row) {
return $row["SUBFUNCTION_ID"];
}
$result = array_map("fetch", $record);
sort($result);
var_dump($result);
在5.3+中你可以做得更好:
$result = array_map(function ($row) { return $row["SUBFUNCTION_ID"]; }, $record);
sort($result);
var_dump($result);
答案 2 :(得分:0)
尝试这样做:
foreach ($array as $row ) {
$response[] = $row["SUBFUNCTION_ID"];
}
print_r($response);