Powerful built-in array functions thanks to PHP
Array_column ();
Array_combine ();
Give me a little chestnut:
<?PHP//Check out the basic information of the user first$userArray= [' id ' = ' = ' Zs ', ' name ' = = ' Zhang San '], [' id ' = ' ls ', ' name ' = ' John Doe '], [' id ' = ' wr ', ' name ' = ' King ']];//make a new user array of the values of a specific column within a two-dimensional array$userArrayNew= Array_column ($userArray, ' ID ');//merges the new user array with the fractional array (gets a new array of fractions) and takes the elements of the first array as the key of the second array element$userArrayCombine=Array_combine($userArrayNew,$userArray);Echo"Re-assembled user array".Php_eol;Var_dump($userArrayCombine);//query out score scores based on ID (in)$scoreArray= [' id ' = ' zs ', ' score ' + 98], [' id ' = ' ls ', ' score ' + ', ' ' id ' = ' wr ', ' score ' + 99]];//Query the list to return, and to take the name on theforeach($scoreArray as&$v) { if(!Empty($userArrayCombine[$v[' ID ']] [' Name '])) { $v[' name '] =$userArrayCombine[$v[' ID ']] [' Name ']; } Else { $v[' name '] = '; }}Echo"Re-assembled fractional array".Php_eol;Var_dump($scoreArray);
PHP is quick and easy to extract a column value of an element in a two-dimensional array as the key of the element in this two-dimensional array