Solved Reorder objects array with its property

Discussion in 'Development' started by Enrico Angelon, Aug 13, 2019.

  1. Enrico Angelon

    Enrico Angelon Spider Jockey

    Messages:
    37
    GitHub:
    herryyt
    Hello everyone, i'm making a Factions plugin but i'm stuck:
    PHP:
    /** @var Faction[] $factions */
    static $factions = [];

    /**
    * Returns factions list (objects).
    *
    * @return Faction[]
    */
    static function getFactions() {
        return 
    self::$factions;
    }
    -------------------------------------------------------------------------------
    PHP:
    public function comparator($object1$object2) {
        return 
    $object1->level $object2->level;
    }

    $value usort(Faction::getFactions(), "comparator");

    var_dump($value);
    ERROR: Only variables should be passed by reference
     
  2. KielKing

    KielKing Zombie

    Messages:
    271
    GitHub:
    kielking
    PHP:
    public function comparator($object1$object2) {
        return 
    $object1->level $object2->level;
    }

    $factions Faction::getFactions();
    $value usort($factions"comparator");

    var_dump($value);
    you can only pass variables in the first parameter of usort()
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.