function sort_test($array){ while(true) { shuffle($array); $temp = array_flip($array); if ($array[2] != 3 && 1 != abs($temp[5] - $temp[6])) { return $array; } }}$array = array(1,2,3,4,5,6);print_r(sort_test($array));
2、编写一个函数实现 将字符串$str=asdfasflasdfopafdsa, 中第一个之出现过一次的字母。function get_target_letter($str){ $i = 0; $array = array(); while(isset($str[$i])) { $array[$str[$i]] = isset($array[$str[$i]]) ? $array[$str[$i]] + 1 : 1; $i ++; } foreach($array as $key=>$val) { if ($val == 1) { return $key; } } return false;}echo get_target_letter('asdfastflasdfopafdsa');
3、有两个表:create table products ( product_id int unsigned not null primary key auto_increment, product_name varchar(64) not null);create table orders ( product_id int unsigned not null , create_at int unsigned not null, num int unsigned not null );
请编写一条sql语句查询出t1-t2时间段间的产品名、销售量总数并按照销售量总数由高到低排序。
我的做法:
select products.product_name, number.numfrom ((select product_id, sum(num) as num from orders where orders.create_at between {$t1} and {$t2} group by product_id) as number) inner join products on products.product_id = number.product_idorder by number.num desc;
这三个题印象比较深刻其它的不太记得了,答案是按照我自己的做法写的,不对的地方请指正
以上就介绍了今天去聚美的几个面试题,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
