php - how to sort array based on value os child array -


below array , want sort based on [attributes]->[0]->[value] how can please guide me. tried using sort how make work value of child array. pls guide me new me.

[549246] => array         (             [info] => array                 (                     [price] => $281.00                     [qty] => 10                     [prod_id] => 549246                 )              [attributes] => array                 (                     [0] => array                         (                             [code] => sizes                             [label] => size                             [value] => 25mg                             [attribute_id] => 191                             [option_id] => 26                         )                  )          )      [549245] => array         (             [info] => array                 (                     [price] => $75.00                     [qty] => 10                     [prod_id] => 549245                 )              [attributes] => array                 (                     [0] => array                         (                             [code] => sizes                             [label] => size                             [value] => 5mg                             [attribute_id] => 191                             [option_id] => 24                         )                  )          ) 

try below;

function customer_sort ($a, $b) {  if ((int)$a['attributes'][0]['value'] == (int)$b['attributes'][0]['value']) {     return 0; }  return (int)$a['attributes'][0]['value'] > (int)$b['attributes'][0]['value'] ? 1 : -1;  } uasort($arr, 'customer_sort'); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -