PHP中多维数组的排序
1.用户定义排序:usort($array, functionName);其中functionName为用户定义的函数名,用户定义的函数指定排序规则,比较数组中两个元素的大小,大于返回正数,小于返回负数,等于返回0。2.反向用户排序:用户定义函数时,比较数组中两个元素的大小,大于返回负数,小于返回正数,等于返回0。$fruits = array(array('APP', 'Apple', 3.2), array('ORG', 'Orange', 2.6),
array('JIM','linina','3.4'));
echo 'Init:
';
foreach($fruits as $key)
{
echo $key['2'];
}
//按名称排序
function compareByName($x, $y) {
if ($x[1] == $y[1]) {
return 0;
}
else if ($x[1] > $y[1]) {
return 1;
} else {
return -1;
}
}
usort($fruits, 'compareBYName');
echo '
Compare By Name:
';
for ($i = 0; $i < 3; $i++) {
for ($j = 0; $j < 3; $j++) {
echo '|'.$fruits[$i][$j];
}
echo '
';
}
//按价格排序
function compareByPrice($x, $y) {
if ($x[2] == $y[2]) {
return 0;
}
else if ($x[2] > $y[2]) {
return 1;
}
else {
return -1;
}
}
usort($fruits, 'compareBYPrice');
echo '
Compare By Price:
';
for ($i = 0; $i < 3; $i++) {
for ($j = 0; $j < 3; $j++) {
echo '|'.$fruits[$i][$j];
}
echo '
';
}
//按价格反向排序
function reverse_compareByPrice($x, $y) {
if ($x[2] == $y[2]) {
return 0;
}
else if ($x[2] > $y[2]) {
return -1;
}
else {
return 1;
}
}
usort($fruits, 'reverse_compareByPrice');
echo '
Reverse Compare By Price:
';
for ($i = 0; $i < 3; $i++) {
for ($j = 0; $j < 3; $j++) {
echo '|'.$fruits[$i][$j];
}
echo '
';
}
?>
相关文档:
<?php
require_once ('unit_tester.php');
require_once ('reporter.php');
require_once ('../config.php');
require_once ('../source\modules\user\user_api.func.php');
require_once ('../source/base_model.class.php');
Class registertest extends UnitTestCase{
public function testAssertEqual(){
$b ......
configure: error: Unable to find libgd.(a|so)
如果使用的是ubuntu或debian就很简单了,直接sudo apt-get install apache2
libapache2-mod-php5 php5 php5-gd 就基本上搞定,但是用源代码安装还是很麻烦~
wget http://www.boutell.com/gd/http/gd-2.0.11.tar.gz
tar zxvf gd-2.0.11.tar.gz
cd gd-2.0.11
sudo . ......
数据库中查询到以下的结果:
cname linename minute
aa c1 & ......