title: How to sort array data as per key value using PHP?
body: <p>I need to sort an array which contains json data as per some key value. I am providing my array below.</p>
  
  <pre><code>$data=[
  {device_type:"1",hit_type:"3",member_id:"96",name:"Gallery",rest_name:"Goro + Gun",summery_id:"22"},
  {device_type:"1",hit_type:"1",member_id:"96",name:"Page",rest_name:"Goro + Gun",summery_id:"22"},
  {device_type:"1",hit_type:"2",member_id:"96",name:"Map",rest_name:"Goro + Gun",summery_id:"22"},
  {device_type:"1",hit_type:"2",member_id:"96",name:"Map",rest_name:"Goro + Gun",summery_id:"22"},
  {device_type:"1",hit_type:"4",member_id:"90",name:"Phone",rest_name:"the livingroom",summery_id:"21"},
  ]
  </code></pre>
  
  <p>I have the array of data which is given above. I need to sort this as per <code>member_id</code> and counts the <code>hit_type</code> and <code>total hit</code> finally it need to save into another array. My expected output array is given below.</p>
  
  <pre><code>$result=[
  {device_type:"1",member_id:"96",Page_hit:"1",Gallery_hit:"1",Map_hit:"2",Phone_hit:"0",Web_hit:"0",rest_name:"Goro + Gun",summery_id:"22",total_hit:"4"},
  {device_type:"1",member_id:"90",Page_hit:"0",Gallery_hit:"0",Map_hit:"0",Phone_hit:"1",Web_hit:"0",rest_name:"the livingroom",summery_id:"21",total_hit:"1"}
  ]
  </code></pre>
  
  <p>The above is my expected output.hit_type will always count as per member_id and the table is given below.</p>
  
  <pre><code>name      type
  Page       1
  Map        2
  Gallery    3
  Phone      4
  Web        5
  </code></pre>
  
  <p>Edit: The query from the comments:</p>
  
  <pre><code>$sql = "
  SELECT s.summery_id,
         s.member_id,
         s.hit_type,
         s.device_type,
         s.counter,
         s.date,
         r.rest_name,
         h‌​.NAME,
         h.type
  FROM   db_analytics_summery AS s
         LEFT JOIN db_hit_type AS h
                ON s.hit_type = h.type
         LEFT JOIN db_restaurant_basic AS r
                ON s.member_id = r.member_id
  ORDER  BY s.summery_id DESC;
  "; 
  </code></pre>