让我们试试下面的代码,
$users = get_all_user_ids(\'\');
$i=0; // initialization
foreach($users as $user) {
$pageview = get_user_meta($user, \'page_visits\', true);
if ($pageview != 0) {
//$popularid[$pageview][\'count\'] = $user; // Err: // Array won\'t be unique due to pageview might be same for multiple users
// $popularid[$user] = $pageview; // Array will be unique based on user id
$popularid[$i][\'user\'] = $user;
$popularid[$i][\'pageview\'] = $pageview;
$i++; // incrementor
}
}
//rsort($popularid); // Sorts based on value
usort($popularid, function($a, $b) {
return $a[\'pageview\'] - $b[\'pageview\'];
});
$userArr = array_column($popularid, \'user\');
//return $popularid;
return $userArr;
Update:的核心PHP代码示例
usort
$array[] = array(\'pageview\'=>4,\'user\'=>\'abc\');
$array[] = array(\'pageview\'=>2,\'user\'=>\'xyz\');
$array[] = array(\'pageview\'=>1,\'user\'=>\'pqrs\');
$array[] = array(\'pageview\'=>3,\'user\'=>\'ijk\');
usort($array, function($a, $b) {
return $a[\'pageview\'] - $b[\'pageview\'];
});
$userArr = array_column($array, \'user\'); // to get only the values from user key
print_r($userArr);