skip to Main Content

Sort array values by their existence in a blacklist array, then alphabetically – PHP

I have the following code: $check = array('person a','person c'); $data = array('person c','person a','person d','person e'); define('check',$check); //asort($data); print'<pre>';print_r($data);print'</pre>'; usort($data,function($a,$b){ return empty(check[$a]) ? 1 : $a <=> $b; }); print'<pre>';print_r($data);print'</pre>'; exit; What I am trying to achieve is: person…

VIEW QUESTION
Back To Top
Search