arrays - How To Sort Empty key & value in lower order if its null in php -


what do i want

  • I need it when [comment] = 'field tap Then it should be sorted & amp; The result will be in the following order.
  • array structure

      [0] = & gt; Array ([type] = & gt; CACDAA [Metadata] => Array ([0] => Hey ([zodiac] => 320 [comment] = & gt;))) [1] = & gt; ; Array ([type] = & gt; CVMA [Metadata] => Array ([0] => Hey ([zodiac] => 320 [comment] = & gt; Onsite, after 20 February) ))  

source code

  unset ($ data [0]); // Store Types and Areas are related to foreach (dollar data $ k => $ v) {$ type [$ v ['type']] [] = $ k; } // loop type, result array foreach ($ type = $ k => $ v) {$ tmp = array ('type' = & gt; $ k, 'metadata' => array ()); // loop this type of foreach ($ w as $ w) {// store in TMP $ t = array ('amount' => $ data [$ w] ['amount'], 'comment' = & Gt; $ data [$ w] ['comment']); $ T Array structure array ([zodiac] => 320 [comment] = & gt; Array ([zodiac] => 320 [comment] => after 20 February onsite) Onsite February 20 (After [zodiac] = & gt; 320 [comment] = & gt; onsite, after 20th February) onsite 20th February [comment] => after 370 [comment] => onsite after 20th February ) After 20 February, Onrite ([zodiac] => 170 [comment] = & gt; onsite after 20th February) // sorted TMP Empty value // UST ($ T, function ($ A, B $) { // if ($ a == '' & amp; $ b! = '') Return 1; // if ($ b == '' & amp; $ a! = '') Return -1; // if ($ b == 0) {return1;} // return 0; //}) ; Arsort ($ t ['comment']); // store $ tmp ['metadata'] [] = $ t; } $ Result [] = $ tmp; }  

After the sorting, the output of the array should come like X

  [1] => Array ([type] = & gt; CVMA [Metadata] => Array ([0] => Hey ([zodiac] => 320 [comment] => February 20 onsite)) [ 0] = & gt; Array ([type] = & gt; cacdaa [metadata] = & gt; array ([0] => hey ([amount] => 320 [comment] => gt;)))  
  • The problem I have also tried with usort.

  • I tried with the arsort function

  • Please tell me why I have done wrong.

  • Sorting me Funk The value for the value and the value in Php.

uasort ($ arrays, function ($ a) {return (is_null ($ a ['metadata'] [0] ['comment']) or $ a [' Metadata '] [0] [' comment '] == "") 1: -1;});


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -