Home  >  Article  >  php教程  >  使用usort对数组进行排序

使用usort对数组进行排序

PHP中文网
PHP中文网Original
2016-05-23 17:10:181014browse

使用usort对数组进行排序

function cmp($a, $b) {
			if ($a['weight'] == $b['weight']) {
				return 0;
			}
			return ($a[&#39;weight&#39;] < $b[&#39;weight&#39;]) ? 1 : -1;
		}
		usort($result,&#39;cmp&#39;);

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Redis Client,单例Next article:AES-256 加密 PHP实现