PHP5.3 more than Array_map use anonymous functions for processing
Code:
<?PHPfunctionArray_col ($arr=Array(),$idx= 0,$newidx= 0){ if(function_exists(' Array_column ') &&!Is_array($idx) &&Is_bool(Strpos($idx, ', ', 1))) { returnArray_column ($arr,$idx,$newidx); } Else { return Array_map(function($element) Use($idx,$newidx) { $ret _arr=Array(); $tmp= !Is_array($idx) &&Is_int(Strpos($idx, ', ', 1)?Explode(‘,‘,$idx): 0; $ntmp= !Is_array($newidx) &&Is_int(Strpos($newidx, ', ', 1)?Explode(‘,‘,$newidx): 0; if(Empty($tmp)) { return $ret _arr; } $TMPC _idx=Count($tmp); $TMPC _newidx=Count($ntmp); if(Is_int($ntmp) ||Empty($ntmp)) { for($i= 0;$i<$TMPC _idx;$i++) { $ret _arr[]=$element[$tmp[$i]]; } } Else { if($TMPC _newidx>=$TMPC _idx) { for($i= 0;$i<$TMPC _newidx;$i++) { $ret _arr[$element[$ntmp[$i]]]=$element[$tmp[$i]]; } } } return $ret _arr; },$arr); }}$a=Array( Array( ' id ' = 2135, ' first_name ' and ' John ', ' last_name ' and ' Doe ', ),Array( ' id ' = = 3245, ' first_name ' = ' Sally ', ' last_name ' and ' Smith ', ) ); Var_export(Array_col ($a, ' Id,last_name ', ' first_name,first_name ')); ?>
Output
<? PHP Array (//Cover up 0 = = array (' John ' = ' Doe ' ), 1 = Array ( ' Sally ' = ' Smith ', ),?>
PHP gets the specified number of columns in the two-dimensional array "with Array_column"