To achieve the requirements:
If the data obtained in the database is:
$pos =[{' word ' => ' vocabulary 1 ', ' value ' => ' weight value 1 '},{' word ' => ' words 2 ', ' value ' => ' weights 2 '},{' word ' => ' words 3 ', ' Value ' => ' Weight value 3 '}];
$neg =[{' word ' => ' vocabulary 4 ', ' Weight value 4 '},{' word ' => ' vocabulary 5 ', ' Value ' => ' right value 5 '},{' word ' => ' vocabulary 6 ', ' Value ' => ' weight value 6 '}];
The interface outputs data in the following form:
$word =[{' word ' => ' vocabulary 1 ', ' value ' => ' weight value 1 ', ' emotion ' =>1},{' word ' => ' vocabulary 2 ', ' value ' => ' weight 2 ', ' emotion ' => 1},{' word ' => ' vocabulary 3 ', ' value ' => ' weight value 3 ', ' emotion ' =>1},{' word ' => ' vocabulary 4 ', ' Value ' => ' weight 4 ', ' Emotion ' =>-1}, {' word ' => ' vocabulary 5 ', ' Value ' => ' weight 5 ', ' emotion ' =>-1},{' word ' => ' vocabulary 6 ', ' Value ' => ' weight 6 ', ' emotion ' =>-1}];
It can be seen that the emotion value of POS positive emotional vocabulary is 1,neg-1.
Specific implementation code:
function Emotion_word ($posWords, $negWords) {function Addkey (& $val, $key, $param) {
$val [$param [' key ']] = $param [' Val ']; Array_walk ($posWords, ' Addkey ', Array (' key ' => ' emotion ', ' Val ' =>1)); The array adds the key value Array_multisort (Array_column ($posWords, ' value '), Sort_desc, $posWords); Arrays are sorted according to value from large to small array_walk ($negWords, ' Addkey ', Array (' key ' => ' emotion ', ' Val ' =>-1)); The array adds the key value Array_multisort (Array_column ($negWords, ' value '), Sort_desc, $negWords); The array is sorted according to value from big to small return array_merge_recursive ($posWords, $negWords); Array Merge}