# 常問面試題
## 算法
### 微信拼手氣紅包算法
```text
function psq($total, $num)
{
$min = 0.01;//每個人最少能收到0.01元
for ($i = 1; $i < $num; $i++) {
$safe_total = ($total - ($num - $i) * $min) / ($num - $i);//隨機安全上限
$money = mt_rand($min * 100, $safe_total * 100) / 100;
$total = $total - $money;
$money_arr[] = $money;
}
$money_arr[] = round($total, 2);
return $money_arr;
}
```
### 抽獎概率算法
### [查找算法](/dataAtructureAlgorithm/algorithm/FIND.html)
### [排序算法](/dataAtructureAlgorithm/algorithm/SORT.html)
### 四個頂點坐標判斷是否是矩形
## php基礎
### session文件內容格式
```text
<?php
session_save_path('./');
session_start();
$_SESSION['name'] = 'shiwenyuan';
$_SESSION['age'] = 100;
// session file_data : name|s:10:"shiwenyuan";age|i:100;
```
### [toString會在什么時候觸發](/backend/php/basics/PHP_STR_MAGIC_METHODS.html#tostring)
### 程序運行結果
#### 題目一
```php
<?php
$arr = [1, 'aa' => 2, 3,4];
foreach($arr as $key => $val) {
echo ($key == 'aa' ? 5 : $val);
}
```
##### 答案
```text
5534
```
## mysql
### 題目一
`table1`
id|name|password
---|---|---
1| AA | asd
2| AA | asd
3| b | asd
4| c | asd
`table2`
id|name
---|---
1| AA
2| AA
3| b
4| c
**select * from table1 as t1 left join table2 as t2 on t1.id = t2.id**查詢結果條數,并說明原因
4條 左表優先
**select * from table1 union select * from table2**查詢結果條數,并說明原因
**select * from table1 union all select * from table2**查詢結果條數,并說明原因
**select id, name from table1 union select id, name from table2**查詢結果條數,并說明原因
## linux
### 統計文件字符串出現的次數
awk '{print $1}' access.log | sort |uniq -c
### 統計文件字符串出現的次數并排序
awk '{print $1}' access.log | sort |uniq -c | sort -rn
### 統計文件字符串出現的次數并排序后前100名
awk '{print $1}' access.log | sort |uniq -c | sort -rn |head -n 100
- 簡介
- php
- php基礎
- php常用數組函數
- php常用字符串函數
- php魔術方法
- php高階
- swoole
- php優化
- workerman
- PHP底層運行機制和原理
- php框架
- laravel
- 前端
- react
- 爬蟲
- Scrapy
- Linux
- IO復用
- nginx
- nginx進程工作原理
- nginx配置
- 正向代理反向代理
- UPSTREAM
- SERVER
- HTTPS
- queue
- kafka
- redis
- DB
- mysql
- 存儲引擎
- 索引
- 鎖
- 觸發器
- 分庫分表
- 三范式
- 負載均衡
- 事務
- EXPLAN
- mysql死鎖
- mysql索引覆蓋與回表
- mysql聚簇索引與非聚簇索引
- NoSql
- memcache
- redis
- mongo
- 網絡協議
- tcp與udp
- https與http
- 架構
- LNMP架構下HTTP請求的調用次序
- 數據結構&算法
- 基礎數據結構
- Linked List
- array
- stack
- queue
- tree
- hash
- heap
- 常見算法
- 排序算法
- 查找算法
- 其他
- php的一些坑
- 常問面試題
- 技術面試最后反問面試官的話
- hr
- redis緩存擊穿、穿透、雪崩
- 面試中回答的不好的問題
- web攻擊防范