$a = Array (' cid ' = 1, ' cname ' = ' about '), Array (' cid ' = 7, ' CNAME ' = ' introduction '), Array (' cid ' = 8, ' cname ' = ' culture '), Array (' cid ' = 9, ' cname ' = ' dynamic '); $b = Array (' cid ' = 1, ' cname ' = ' about '), Arra Y (' cid ' = 2, ' cname ' = ' opera '), Array (' cid ' = 3, ' cname ' = ' US drama ') ), Array (' cid ' = 4, ' cname ' = ' video '), Array (' cid ' = 5, ' CNAME ') = ' entertainment '), Array (' cid ' = 6, ' cname ' = ' contact '), Array (' cid ' = 7, ' CNAME ' = ' profile '), Array (' cid ' = 8, ' cname ' = ' culture '), Array (' CID ' = 9, ' cname ' = ' dynamic '), $c = Array (' cid ' = 1, ' cname ' = ' about '), Array (' CID '= 7, ' cname ' = ' profile '), Array (' cid ' = 8, ' cname ' = ' culture '), Array ( ' CID ' = 9, ' cname ' = ' dynamic '), Array (' cid ' = + 2, ' cname ' = ' opera '), Array (' cid ' = 3, ' cname ' = ' US drama '), Array (' cid ' = + 4, ' cname ' = = ') Video '), Array (' cid ' = 5, ' cname ' = ' entertainment '), Array (' cid ' = + 6, ' CN Ame ' = ' contact ');
Known as $ A, refer to $ A to sort $b into $c.
Reply content:
$a = Array (' cid ' = 1, ' cname ' = ' about '), Array (' cid ' = 7, ' CNAME ' = ' introduction '), Array (' cid ' = 8, ' cname ' = ' culture '), Array (' cid ' = 9, ' cname ' = ' dynamic '); $b = Array (' cid ' = 1, ' cname ' = ' about '), Arra Y (' cid ' = 2, ' cname ' = ' opera '), Array (' cid ' = 3, ' cname ' = ' US drama ') ), Array (' cid ' = 4, ' cname ' = ' video '), Array (' cid ' = 5, ' CNAME ') = ' entertainment '), Array (' cid ' = 6, ' cname ' = ' contact '), Array (' cid ' = 7, ' CNAME ' = ' profile '), Array (' cid ' = 8, ' cname ' = ' culture '), Array (' CID ' = 9, ' cname ' = ' dynamic '), $c = Array (' cid ' = 1, ' cname ' = ' about '), Array (' CID '= 7, ' cname ' = ' profile '), Array (' cid ' = 8, ' cname ' = ' culture '), Array ( ' CID ' = 9, ' cname ' = ' dynamic '), Array (' cid ' = + 2, ' cname ' = ' opera '), Array (' cid ' = 3, ' cname ' = ' US drama '), Array (' cid ' = + 4, ' cname ' = = ') Video '), Array (' cid ' = 5, ' cname ' = ' entertainment '), Array (' cid ' = + 6, ' CN Ame ' = ' contact ');
Known as $ A, refer to $ A to sort $b into $c.
Use the custom sort function Usort
ref = $ref; $this->array = $array; usort($this->array,function($t1,$t2){ $p1 = array_search($t1,$this->ref); $p2 = array_search($t2,$this->ref); if(($p1===false||$p1===null) && ($p2===false||$p2===null)) return array_search($t1,$this->array)array) ? -1 :1; if($p1===$p2) return 0; if($p1===false||$p1===null) return 1; if($p2===false||$p2===null) return -1; return $p1<$p2 ? -1 : 1; }); } }//----------------------$res = new SortByArray($a,$b);print_r($res->array);?>
This should be a multi-dimensional array ordering problem, PHP Array_multisort can be used for multidimensional array sorting.
The specific implementation of the code will not write, you can look at the manual to ponder.
/** * [Onearrayto two-dimensional array is sorted by an array value one-to-many] * @param [type] $a [reference array] * @param [Type] $b [This is the array to be sorted] * @param [Type] $keyword [key value] * @return [type] [description] */function onearrayto ($a, $b, $keyword) {$newa = array (); foreach ($a as $key = + $value) {$newa [] = $value [$keyword]; } $newa = Array_flip ($newa); $NEWB = Array (); foreach ($b as $key = + $value) {$NEWB [] = $value [$keyword]; } $NEWB = Array_flip ($NEWB); $d = $NEWB; foreach ($newb as $k + $v) {foreach ($newa as $key + = $value) {if ($key = = $k) { Unset ($d [$k]); }}} $c = Array_flip ($newa); $d = Array_flip ($d); $p = Array_merge ($c, $d); $p = Array_flip ($p); $NEWBB = Array (); foreach ($b as $key = + $value) {$NEWBB [$value [$keyword]] = $value; } $g = Array (); foreach ($p as $key = + $value) {$g [] = $NEWBB [$key]; } return $g;}
Write your own, although it is a stupid method.