There are two arrays: {code ...} how to sort the second array by the key value of the first array, that is, the second array is changed to id, name, identityId... use the system function. thank you for the following two arrays:
Array (size = 6) 0 => string 'id' (length = 2) 1 => string 'name' (length = 4) 2 => string 'identityid' (length = 10) 3 => string 'phone' (length = 5) 4 => string 'email '(length = 5) 5 => string 'schoolid' (length = 8) array (size = 6) 'id' => string 'unique identifi' (length = 12) 'identityid' => string 'id' (length = 9) 'phone' => string 'mobile phone no. '(length = 9) 'email '=> string 'mailbox' (length = 6) 'name' => string 'name' (length = 6) 'schoolid' => string 'school' (length = 6)
How to sort the second array by the key value of the first array, that is, change the second array to id, name, identityId ····
Thank you for using the system functions.
Reply content:
There are two arrays:
Array (size = 6) 0 => string 'id' (length = 2) 1 => string 'name' (length = 4) 2 => string 'identityid' (length = 10) 3 => string 'phone' (length = 5) 4 => string 'email '(length = 5) 5 => string 'schoolid' (length = 8) array (size = 6) 'id' => string 'unique identifi' (length = 12) 'identityid' => string 'id' (length = 9) 'phone' => string 'mobile phone no. '(length = 9) 'email '=> string 'mailbox' (length = 6) 'name' => string 'name' (length = 6) 'schoolid' => string 'school' (length = 6)
How to sort the second array by the key value of the first array, that is, change the second array to id, name, identityId ····
Thank you for using the system functions.
'Unique identifi', 'identityid' => 'id', 'phone' => 'mobile phone number', 'Email '=> 'mailbox ', 'name' => 'name', 'schoolid' => 'school']; var_dump (array_merge (array_flip ($ a), $ B ));
Use the system function array_muiltsort
$ Arr1 = array ('id', 'name', 'identityid', 'phone', 'Email ', 'schoolid '); $ arr2 = array ('id' => 'unique identifi', 'identityid' => 'id', 'phone' => 'mobile phone number ', 'email '=> 'mailbox', 'name' => 'name', 'schoolid' => 'school',); array_multisort ($ arr1, SORT_DESC, $ arr2 ); print_r ($ arr2); // The result is: array ([schoolId] => School [email] => email [identityId] => id card [phone] => mobile phone number [id] => unique id [name] => name)
$ A = ['id', 'name', 'identityid', 'phone', 'Email ', 'schoolid'];
$ B = ......;
Foreach ($ a as $ v ){
$c[$v] = $b[$v];
}
$ C is the array you want;
$c = array();foreach ($a as $value) $c[$value] = $b[$value];print_r($c);