I
I
Ilya Beloborodov2015-10-24 21:33:10
Yii
Ilya Beloborodov, 2015-10-24 21:33:10

How to apply array_multisort to given array?

Good evening. So, I've been reading about array_multisort all evening, I can't understand how it works. Can you tell me how to apply this function to this array so that the nested arrays are sorted by 'nomatch' in ascending order?

array(8) {
  [1]=>
  array(5) {
    ["nomatch"]=>
    int(0)
    ["name"]=>
    string(10) "text1"
    ["people"]=>
    int(2)
    ["needle"]=>
    bool(false)
    ["resources"]=>
    array(4) {
      [0]=>
      int(31)
      [1]=>
      int(12)
      [2]=>
      int(10)
      [3]=>
      int(9)
    }
  }
  [2]=>
  array(5) {
    ["nomatch"]=>
    int(0)
    ["name"]=>
    string(10) "text2"
    ["people"]=>
    int(2)
    ["needle"]=>
    bool(false)
    ["resources"]=>
    array(4) {
      [0]=>
      int(31)
      [1]=>
      int(12)
      [2]=>
      int(10)
      [3]=>
      int(9)
    }
  }
  [3]=>
  array(5) {
    ["nomatch"]=>
    int(0)
    ["name"]=>
    string(14) "text3"
    ["people"]=>
    int(2)
    ["needle"]=>
    bool(false)
    ["resources"]=>
    array(4) {
      [0]=>
      int(31)
      [1]=>
      int(12)
      [2]=>
      int(10)
      [3]=>
      int(9)
    }
  }
  [4]=>
  array(5) {
    ["nomatch"]=>
    int(0)
    ["name"]=>
    string(23) "text4"
    ["people"]=>
    int(2)
    ["needle"]=>
    bool(false)
    ["resources"]=>
    array(4) {
      [0]=>
      int(31)
      [1]=>
      int(12)
      [2]=>
      int(10)
      [3]=>
      int(9)
    }
  }
  [5]=>
  array(5) {
    ["nomatch"]=>
    int(0)
    ["name"]=>
    string(14) "text5"
    ["people"]=>
    int(2)
    ["needle"]=>
    bool(false)
    ["resources"]=>
    array(4) {
      [0]=>
      int(31)
      [1]=>
      int(12)
      [2]=>
      int(10)
      [3]=>
      int(9)
    }
  }
  [6]=>
  array(5) {
    ["nomatch"]=>
    int(1)
    ["name"]=>
    string(14) "text6"
    ["people"]=>
    int(2)
    ["needle"]=>
    array(1) {
      ["Казарма"]=>
      int(2)
    }
    ["resources"]=>
    array(4) {
      [0]=>
      int(31)
      [1]=>
      int(12)
      [2]=>
      int(10)
      [3]=>
      int(9)
    }
  }
  [7]=>
  array(5) {
    ["nomatch"]=>
    int(1)
    ["name"]=>
    string(25) "text7"
    ["people"]=>
    int(2)
    ["needle"]=>
    array(2) {
      ["text8"]=>
      int(1)
      ["text9"]=>
      int(1)
    }
    ["resources"]=>
    array(4) {
      [0]=>
      int(31)
      [1]=>
      int(12)
      [2]=>
      int(10)
      [3]=>
      int(9)
    }
  }
  [8]=>
  array(5) {
    ["nomatch"]=>
    int(1)
    ["name"]=>
    string(22) "text10"
    ["people"]=>
    int(2)
    ["needle"]=>
    array(1) {
      ["text11"]=>
      int(10)
    }
    ["resources"]=>
    array(4) {
      [0]=>
      int(31)
      [1]=>
      int(12)
      [2]=>
      int(10)
      [3]=>
      int(9)
    }
  }
}

(in the example, the array is sorted as it should, but sometimes not). I will be grateful for help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Beloborodov, 2015-10-24
@kowap

Everything, went to the toilet and received his sight.

$arr=......// массив который нужно сортировать
$co=[];
      foreach($arr as $item){
        $co[]=$item['nomatch'];
      }
      array_multisort($co, SORT_ASC, $arr);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question