This is often the case, although sometimes we can sort the data directly when the database is queried, but we can't meet the increasingly complex business requirements. Two functions are used here, one is the Array_column () function, and this function accepts three parameters. For details, see here is the value of extracting a key from a two-dimensional array, returned as a new array.
The other is the Array_multisort () function, which is a sort function, see here for details
It sorts the third parameter according to the collation of the first parameter array, according to the value of the first parameter array, at the third parameter weight position.
You don't get it, do you? If you do not understand the right, or directly read the code to the reality:
$orgin = Array ( ' id ' = = 5698, ' first_name ' = ' Bill ', ' last_name ' = ' Gates ', ), Array ( ' id ' = = 4767, ' first_name ' = ' Steve ', ' last_name ' = ' Jobs ', ), Array ( ' id ' = = 3809, ' first_name ' + ' Mark ', ' last_name ' = ' Zuckerberg ', ') ; $idArr = Array_ Column ($orgin, ' id '); Array_multisort ($IDARR, SORT_ASC, $orgin); Var_dump ($orgin);
The result of this printing is:
array (size=3) 0 = = Array (size=3) ' id ' = = int 3809 ' first_name ' = = String ' Mark ' (length=4) ' last_name ' = ' + string ' Zuckerberg ' (length=10) 1 = array (size=3) ' id ' = ' + int 4767 ' first_name ' + string ' Steve ' (length=5) ' last_name ' = = String ' Jobs ' (length=4) 2 =& Gt Array (size=3) ' id ' = = int 5698 ' first_name ' and string ' Bill ' (length=4) ' last_name ' = + string ' Ga TEs ' (length=5)