1

Before i use array_multisort, execute my query and use loop for output my problem evertime use array_multisort , it gives me this error.

Fatal error: Allowed memory size of 549453824 bytes exhausted (tried to allocate 524288 bytes)

Update : in my php.ini memory_limit is 1024 and i do not want to do it anymore !

$result = $query->execute();

while( $record = $result->fetchAssoc() ) { 
    $items[] = $record;
}

// Sort by Order_id
 array_multisort(array_column($items, 'nid'), SORT_DESC,
            array_column($items, 'order_id'),      SORT_ASC,
            $items);

UPDATE 2 :

After this i use this

    foreach ($items as $row) {

      $hash[$row['nid']] = $row;
      $name[$row['nid']][] = $row['name'];
      $hash[$row['nid']]['name'] = array_unique($name[$row['nid']]);

      $tagname[$row['nid']][] = $row['tagsdata_name'];
      $hash[$row['nid']]['tagsdata_name'] = array_unique($tagname[$row['nid']]);

      $file[$row['nid']][] = $row['filename'];
      $hash[$row['nid']]['filename'] = array_unique($file[$row['nid']]);
    }
    $resultfinal = ($hash);

    array_multisort(//array_column($resultfinal, 'producttitle_title'), SORT_DESC,
                    array_column($resultfinal, 'created'),      SORT_DESC,
                    array_column($resultfinal, 'changed'),      SORT_DESC,
                    $resultfinal);
Bijan Zand
  • 415
  • 4
  • 14
  • What you are doing via PHP, I am sure you could do that by an SQL query. Can you gives us more context of what query was executed and what is the purpose of the query? – nice_dev Dec 30 '18 at 10:03
  • Possible duplicate of https://stackoverflow.com/questions/6555194/fatal-error-allowed-memory-size-of-134217728-bytes-exhausted-tried-to-allocate ? – nice_dev Dec 30 '18 at 10:04
  • How many records do you have in `$result`? if you use simple sort function do you also gets this error? – dWinder Dec 30 '18 at 10:04
  • my out items should be 20 item per page @DavidWinder – Bijan Zand Dec 30 '18 at 10:07
  • @vivek_23 not duplicate dude..my memory limit is 1024 ! – Bijan Zand Dec 30 '18 at 10:08
  • Did you try to run this as stand-alone code in other machines? – dWinder Dec 30 '18 at 10:09
  • Possible duplicate of [Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)](https://stackoverflow.com/questions/6555194/fatal-error-allowed-memory-size-of-134217728-bytes-exhausted-tried-to-allocate) – Shashwat Dec 30 '18 at 10:10
  • @DavidWinder yes code is right but when my out is lot memory gives a error ! – Bijan Zand Dec 30 '18 at 10:12
  • Does simple sort function also fails or only `array_multisort`? – dWinder Dec 30 '18 at 11:33
  • @DavidWinder Just array_multisort gives error – Bijan Zand Dec 30 '18 at 12:08
  • Then I would suggest to use `array_multisort` on narrowed array and then use the keys. I guess you have `$record["id"]`? – dWinder Dec 30 '18 at 12:25
  • Mr @DavidWinder Update my Problem . see – Bijan Zand Dec 30 '18 at 12:52
  • I'm little bit confuse - does the error come at the first or the second `array_multisort`? And what is the propose of the `foreach`? you add data to each row and then calling `array_multisort` again? – dWinder Dec 30 '18 at 12:57

0 Answers0