¼Ç¼¼¯³¬Ç¿´¦Àíº¯Êýarray_columnµÄÉý¼¶°æʵÏÖ
Ó¦Óó¡¾°£ºÖ÷ÒªÓÃÀ´´¦Àí¼Ç¼¼¯£¨¶þάÊý×飩
1¡¢ÕûºÏ½á¹û¼¯£¨Ò»Î¬Êý×飬Èçids£º[1,3,4,5]£¬»ñ½±Óû§ÃûÇåµ¥£º['ÐÜÃ÷','lijia','¶þÀÉÉñ']£©
2¡¢×éºÏ¼üÖµ¶Ô£¨Ò»Î¬Êý×飬Èç±êÇ©£ºarray('mysql'=>'url1','php'=>'url2']£©
3 ¡¢»º´æÎļþÊý¾Ý£¨id=>info£©
×¢ÒâÊÂÏphp5.5°æ±¾ÒÔ×÷ΪÄÚÖú¯Êý£¬Ê¹ÓÃÇ°Çë×¢ÒâÃüÃû³åÍ»¡£
From(EQPHP¹¤¾ßÀà)£ºhttps://github.com/eqphp/framework/blob/master/www/class/fun.php
ÑÝʾ×÷Æ·£ºhttp://www.eqphp.com/blog/list/
´úÂëÈçÏ£º
//´¦Àí¼Ç¼¼¯(php5.5ÄÚÖÃ)
static function array_column($data,$key='id',$column=null){
$buffer=null;
if ($column) {
//k=>v
if (strpos($column,',') === false) {
foreach ($data as $value) {
$buffer[$value[$key]]=$value[$column];
}
return $buffer;
}
//k=arr
$field=explode(',',$column);
foreach ($data as $value) {
$id=$value[$key];
array_walk($value,function ($v,$k) use (&$value,$field){
if (!in_array($k,$field)) unset($value[$k]);
});
$buffer[$id]=$value;
}
return $buffer;
}
//id_arr
foreach ($data as $value) {
$buffer[]=$value[$key];
}
return $buffer;
}
//Ó÷¨demo£º
//ԼǼ¼¯£º
$data=array(
array('id'=>1,'name'=>'dubox','age'=>25,'girlfriend'=>'ËÕ´òÂÌ')£¬
array('id'=>4,'name'=>'С´º×Ó','age'=>21,'girlfriend'=>'²»ÖªµÀ')£¬
array('id'=>9,'name'=>'°×³Õ','age'=>71,'girlfriend'=>'¹Ñ¸¾')£¬
);
$ids=array_column($data,'id');
//out: array(1,4,9);
$info=array_column($data,'name','girlfriend');
//out: array('dubox'=>'ËÕ´òÂÌ','С´º×Ó'=>'²»ÖªµÀ','°×³Õ'=>'¹Ñ¸¾');
$cache=array_column($data,'id','name,age,girlfriend');
//out: array(
1=>array('name'=>'dubox','age'=>25,'girlfriend'=>'ËÕ´òÂÌ')£¬
4=>array('name'=>'С´º×Ó','age'=>21,'girlfriend'=>'²»ÖªµÀ')£¬
9=>array('name'=>'°×³Õ','age'=>71,'girlfriend'=>'¹Ñ¸¾')£¬
);
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ