1、编写一个函数将1,2,3,4,5,6随机放到一个数组,3不能在第三的位置,5和6不能挨着。
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));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');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.num
FROM ((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_id
ORDER BY number.num DESC;以上就介绍了今天去聚美的几个面试题,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号