0

I want to sort an multidimensional array, which has strings as keys and objects as values.

At the moment, this is my code for sorting:

$order = $name = Array();
foreach(get_declared_classes() as $class){
    if(get_parent_class($class) == "PaymentGateway"){
        $this->gateways[$class::$shortName] = new $class($language);
        if($this->gateways[$class::$shortName]->isActive())
            $order[$class::$shortName] = intval($this->gateways[$class::$shortName]->getSettings()['order']);
        else
            $order[$class::$shortName] = 1000;
        $name[$class::$shortName] = $this->gateways[$class::$shortName]->getLang('name');
    }
}

array_multisort($this->gateways, SORT_ASC, $order, SORT_ASC, $name);

As you can see, the keys of $this->gateways, $order and $name are the same. But it does not work. Does anybody see the mistake?


Debug information:

$name

array(6) { 
      ["barzahlen"]=> string(9) "Barzahlen" 
      ["bitcoin"]=> string(7) "Bitcoin" 
      ["paypal"]=> string(6) "PayPal" 
      ["sofort"]=> string(23) "Sofort-Überweisung" 
      ["stripe"]=> string(6) "Stripe" 
      ["transfer"]=> string(16) "Überweisung" 
  }

$order

array(6) { 
      ["barzahlen"]=> int(4) 
      ["bitcoin"]=> int(5) 
      ["paypal"]=> int(1) 
      ["sofort"]=> int(2) 
      ["stripe"]=> int(3) 
      ["transfer"]=> int(0) 
  }

$this->gateways

To long, the same as before...

Richard
  • 2,772
  • 3
  • 20
  • 36
  • 1
    What _does not work_? – AbraCadaver Jun 03 '15 at 15:28
  • @AbraCadaver: It is the same as before – Richard Jun 03 '15 at 15:31
  • @RiggsFolly: I will add it, but I will short the var_dump output before. Give me a few minutes. – Richard Jun 03 '15 at 15:34
  • @RiggsFolly: Where is your problem with my question? Sorry, but I provided this information: 1. The keys are the same (as you can see in the code example) 2. You can see the `$order` array 3. You can see the `$name` array. I want to sort the `$this->gateways` array with `$order` first and then with `$name`. But it does not work, the sorting is just the same. It either does not work if I only sort by one Array. Your last answer does not helps me. – Richard Jun 03 '15 at 15:41
  • Forget `array_multisort` and implement a `uasort` custom comparison function. See the duplicate. – deceze Jun 03 '15 at 15:47

0 Answers0