1.php比較實用的二維陣列函式,array_combine(), array_column()實現資料的組裝
$orderinfo = array(
array('userid' => 12, 'mobile' => 18317776781, 'order_code' => 123),
array('userid' => 15, 'mobile' => 18317776791, 'order_code' => 124),
array('userid' => 13, 'mobile' => 18317776793, 'order_code' => 121),
array('userid' => 12, 'mobile' => 18317776793, 'order_code' => 122),
);$userinfo = array(
array('userid' => 12, 'name' => 'a', 'age' => 20),
array('userid' => 13, 'name' => 'b', 'age' => 21),
array('userid' => 14, 'name' => 'c', 'age' => 22),
);$userinfo = (array_combine(array_column($userinfo, 'userid'), $userinfo));
foreach ($orderinfo as $key => $value)
echo '';
var_dump($orderinfo);die;
2.改變陣列中所有的值
二維陣列的排序問題
//二位陣列根據指定的字段進行排序
$studentinfo = array(
array('id' => 35, 'name' => 'liyanping', 'age' => 25),
array('id' => 20, 'name' => 'yanping', 'age' => 20),
array('id' => 16, 'name' => 'ziyanping', 'age' => 26),
array('id' => 36, 'name' => 'piyanping', 'age' => 18),
);$keyarr = array_column($studentinfo, 'id');
array_multisort($keyarr, sort_desc, $studentinfo);
3.陣列去重做標記,多用於excel導資料
//陣列中個別字段值相同該資料重複做標記
$arrlist = array(
array('class_code' => '01', 'mobile' => 18317776781, 'addtime' => '2018-11-03 10:00:12'),
array('class_code' => '02', 'mobile' => 18317776701, 'addtime' => '2018-11-03 10:00:12'),
array('class_code' => '01', 'mobile' => 18317776780, 'addtime' => '2018-11-03 10:00:12'),
array('class_code' => '04', 'mobile' => 18317776780, 'addtime' => '2018-11-03 10:00:12'),
array('class_code' => '05', 'mobile' => 18317776780, 'addtime' => '2018-11-03 10:00:12'),
array('class_code' => '06', 'mobile' => 18317776781, 'addtime' => '2018-11-03 10:00:12'),
array('class_code' => '07', 'mobile' => 18317776782, 'addtime' => '2018-11-03 10:00:12'),
array('class_code' => '09', 'mobile' => 18317776783, 'addtime' => '2018-11-03 10:00:12'),
array('class_code' => '09', 'mobile' => 18317776784, 'addtime' => '2018-11-03 10:00:12'),
array('class_code' => '10', 'mobile' => 18317776785, 'addtime' => '2018-11-03 10:00:12'),
array('class_code' => '11', 'mobile' => 18317776786, 'addtime' => '2018-11-03 10:00:12'),
array('class_code' => '12', 'mobile' => 18317776787, 'addtime' => '2018-11-03 10:00:12'),
);foreach ($arrlist as $key => $value) else
}}
PHP除錯小技巧
在開發機環境只能只能使用vim和emacs 我用的是emacs 除錯php沒有什麼比較的工具,下面是我常用的乙個函式 file put contents tmp my.log print r array date y m d h i s line method true 該函式可以向 tmp my....
php常見小技巧
分割時間 if empty post date else 獲取當天開始到結束 time date y m d start date y m d 00 00 00 end date y m d h i s strtotime time 86399 select from unixtime 146496...
php上線小技巧
1.不希望執行包括system 等在那的能夠執行命令的php函式,或者能夠檢視php資訊的 phpinfo 等函式,那麼我們就可以禁止它們 disable functions system,passthru,exec,shell exec,popen,phpinfo 2.開啟magic quotes...