Created
December 15, 2017 07:25
-
-
Save yusureabc/5ffa66586c70bef94db0c97133efb683 to your computer and use it in GitHub Desktop.
用二维数组的某个元素做key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 用二维数组的某个元素做key | |
*/ | |
function replace_array_key( $data, $field, $append = [] ) | |
{ | |
$result = []; | |
foreach ( (array)$data as $key => $val ) | |
{ | |
$append && $val = $val + $append; | |
$result[ $val[$field] ] = $val; | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment