Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved help with array key

Comments in 'Plugin Development' started by ahoj_truhliku, Jul 19, 2015.

  1. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
    please how can i get e.g. the last key in array.

    PHP:
    $array1 = [=> "one"=> "two"=> "three"];

    $array2 = [=> 65=> 484=> 474];

    sort($array2)
    and now i want to get index from array1 using the last key from array2
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Actually, there is a function called ksort and another called aksort.

    Anyway, end(array_keys($array2))
    ahoj_truhliku likes this.
  3. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
    it should return map name, but it return index or some integer or not? xD
    so what is wrong please? i didnt find anything.
    PHP:
    public $allVotes = ['BedWars1''BedWars2''Chinese''Kingdoms''Nether''STW5'];
    public 
    $stats = [];

    $this->currentTable array_rand($this->allVotes3);
    $this->stats = [=> 4=> 5=> 1];
    $stats $this->stats;

    sort($this->stats);
    $map $this->currentTable[array_keys($stats)[2] - 1]; //$map should be map one name from allVotes but it is integer
  4. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
    i now i need set currentTable keys to 0, 1, 2 instead of key of map. but how?
  5. ahoj_truhliku
    Offline

    ahoj_truhliku Banned

    Joined:
    Jul 9, 2015
    Posts:
    89
    Minecraft User:
    Creeperface001
    Yay i fidn out a way :D

Share This Page

Advertisement