memo.xight.org

日々のメモ

連想配列をキーでソートして走査

サンプル

$fruits = array (
	"d"=>"lemon",
	"a"=>"orange",
	"b"=>"banana",
	"c"=>"apple"'
);
ksort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
	echo "$key = $val\n";
}

出力

a = orange
b = banana
c = apple
d = lemon

Reference

PHP Manual - ksort