我有阵列
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.home, menu);
searchItem = menu.findItem(R.id.menu_item_search_places);
searchItem.setIcon(FontIconDrawable.inflate(getContext(), R.xml.ic_search));
searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setOnSuggestionListener(this);
searchView.setOnQueryTextListener(this);
MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// my stuff are here
return true;
}
});
}
我需要从点数最高的数组中获取Array (
[1] => Array (
[message_id] => 1,
[points] => 3,
)
[2] => Array(
[message_id] => 2,
[points] => 2,
)
[3] => Array(
[message_id] => 3,
[points] => 2,
)
)
值。
答案 0 :(得分:0)
您可以在数组中循环并检查点以找到最高点
$points = 0;
foreach($array as $val) {
if($val['points'] > $points) {
$points = $val['points'];
$message_id = $val['message_id'];
}
}
echo $message_id;
//prints 1
答案 1 :(得分:0)
你可以这样做:
$array = array(
1 => array(
'message_id' => 1,
'points' => 3,
),
2 => array(
'message_id' => 2,
'points' => 2,
),
3 => array(
'message_id' => 3,
'points' => 2,
),
);
$highest = 0;
foreach ($array as $key => $arr) {
if($arr['message_id'] > $highest) {
$highest = $arr['message_id'];
}
}
echo "Highest: " . $highest;
$highest
号码的输出为:3。