usort

Pass extra parameters to usort callback

百般思念 提交于 2019-11-26 12:27:27
问题 I have the following functions. WordPress functions, but this is really a PHP question. They sort my $term objects according to the artist_lastname property in each object\'s metadata. I want to pass a string into $meta in the first function. This would let me reuse this code as I could apply it to various metadata properties. But I don\'t understand how I can pass extra parameters to the usort callback. I tried to make a JS style anonymous function but the PHP version on the server is too

Sorting multidim array: prioritize if column contains substring, then order by a second column

余生颓废 提交于 2019-11-26 07:48:59
问题 I am currently creating a sorting method that consists of values from an mysql query. Here\'s a brief view of the array: Array ( [0] => Array ( [\'id\'] = 1; [\'countries\'] = \'EN,CH,SP\'; ) [1] => Array ( [\'id\'] = 2; [\'countries\'] = \'GE,SP,SV\'; ) ) I have succeeded in making a normal usort based on the numeric id values, but I rather want to sort the array by the content of the \"countries\" field (if it contains a set string, a country code in this case), and then by the id field.