【发布时间】:2018-07-26 20:57:36
【问题描述】:
如何按降序对值进行排序?我试过 arsort();但在我的情况下它不起作用:
$text1 = 'Android SDK, application, familiar with MVP architecture, android studio, angular, angular js';
$skill = array("android sdk"=>"3", "application"=>"1", "angular"=>"2", "android studio"=>"3", "angular js"=>"3");
foreach ($skill as $skills => $weight) {
if (preg_match_all("~\b$skills\b~i", $text1, $matchWords)) {
$matchWords = $matchWords[0];
$matchWords = array_unique($matchWords);
}
$text2 = 'Native Android development';
// Filter $words, keep only the items that are not present in $text2
$missing = array_filter(
$matchWords,
function($w) use ($text2) {
// return TRUE when $w is not in $text
return preg_match('/\b'.preg_quote($w, '/').'\b/i', $text2) == 0;
});
$weight = array($weight);
$dev = array_combine($missing, $weight);
arsort($dev);
foreach($dev as $x => $x_value)
echo "Key: " . $x . " Value: " . $x_value;
echo "<br>";
}
输出:
键:Android SDK 值:3 关键:应用价值:1 键:角度值:2 键:android studio 值:3 键:angular js 值:3
但我想得到这个结果:
键:Android SDK 值:3 键:android studio 值:3 键:角度 js 值:3 键:角度值:2 键:应用值:1
编辑:
我没有按照建议找到答案here。
【问题讨论】: