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

Solved Get name of array

Comments in 'Plugin Development' started by Lexo, Apr 7, 2016.

  1. Lexo
    Offline

    Lexo New Member

    Joined:
    May 25, 2015
    Posts:
    19
    Minecraft User:
    Lexo
    I've got this config:
    Code:
    name1:
    - hello
    - hi
    name2:
    - key
    - nothing
    How I can to know names of root arrays ("name1" and "name2")?

    This not working
    Code:
    $arr = $conf->getAll();
    echo(implode(" ",$arr));
  2. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    PHP:
    $name1 $this->getConfig()->getNested("name1");
    //$name1 will be an array.
    echo $name1[0];
    //Will output "hello". Of course, use something else than echo.
  3. Lexo
    Offline

    Lexo New Member

    Joined:
    May 25, 2015
    Posts:
    19
    Minecraft User:
    Lexo
    Emmm, I must know NAME OF ARRAY, not KEYS
  4. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Um, do you mean you want to get "hello"?
  5. Lexo
    Offline

    Lexo New Member

    Joined:
    May 25, 2015
    Posts:
    19
    Minecraft User:
    Lexo
    No. I want to get "name1" and "name2" in echo....
  6. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Use array_keys.
    PEMapModder and Lexo like this.
  7. Lexo
    Offline

    Lexo New Member

    Joined:
    May 25, 2015
    Posts:
    19
    Minecraft User:
    Lexo
    How?
  8. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    It would be better if you searched it up on Google, but:
    PHP:
    $nameArray $this->getConfig()->getAll();
    $keyArray array_keys($nameArray);
    echo 
    $keyArray[0];
    //Echoes "name1"
    PEMapModder and Lexo like this.
  9. Lexo
    Offline

    Lexo New Member

    Joined:
    May 25, 2015
    Posts:
    19
    Minecraft User:
    Lexo
    Thanks!))

Share This Page

Advertisement