0

I am looping over an array of values building another array as the code below shows:

foreach ($mdl->info()['metadata'] as $info) {
    $fields[] = [
        'name'    => strtolower($info['COLUMN_NAME']),
        'title'   => ucfirst(strtolower($info['COLUMN_NAME'])),
        'type'    => $grid_type_mapper[$info['DATA_TYPE']],
        'width'   => $info['LENGTH'],
        'sorting' => true,
        'editing' => false,
    ];
}

One of the key existing on $info is COLUMN_POSITION and I want to sort the resulting array $fields by this COLUMN_POSITION, how?

ReynierPM
  • 15,161
  • 39
  • 158
  • 314
  • `usort()` is probably good to look at.. *"sort the resulting array `$fields` by this ..... "*. - sort in what way? You are not specifying that. – Nytrix Feb 09 '17 at 23:24
  • @Nytrix `COLUMN_POSITION` is just a number I want to sort by such number DESC – ReynierPM Feb 09 '17 at 23:25
  • 2
    Note: your code doesn't show `$info['COLUMN_POSITION']` being copied to the new array, so sorting by it is going to be (unnecessarily) tricky. Add it in, sort by it, and then loop through and `unset()` it from each element if it's really necessary for it not to be in the final result.. – IMSoP Feb 09 '17 at 23:29
  • If `COLUMN_POSITION` is unique, you can use it as the key as you build `$fields`, and then `krsort`. – Don't Panic Feb 09 '17 at 23:40

0 Answers0