$left = array('A'=>'9','23'=>7,'B'=>'15');
$right = array('C'=>19,'13'=>'27','E'=>'25');
//重组数组,以value排序
$arr = $left+$right;
$new = array();
foreach ($arr as $k => $v) {
$new[] = (int)$v;
}
$res = maopao($new);
$res =implode(" ",$res);
dump($res);
function maopao($arr)
{
$count = count($arr);
$temp = 0;
for ($i=1; $i < $count; $i++) {
for ($j=0; $j < $count-$i; $j++) {
if($arr[$j]>$arr[$j+1]){
$temp = $arr[$j];
$arr[$j] = $arr[$j+1];
$arr[$j+1] = $temp;
}
}
}
return $arr;
}
$arr = array('12'=>array('name'=>'zhangsan','city'=>'guangzhou'),'24'=>array('name'=>'lisi','city'=>'shanghai'));
// 输出:
// NO12:zhangsan live in guangzhou
// NO24:lisi live in shanghai
foreach ($arr as $k => $v) {
echo 'NO'.$k.':'.$v['name'].' '.'live in'.' '.$v['city'].'
';
}
标签:count,arr,res,面试,live,foreach,array,php
来源: https://blog.csdn.net/zdklhh/article/details/89532790