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

Arrays in PHP

Comments in 'Plugin Development' started by Radix, Jul 10, 2015.

  1. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    I was reading over the PHP Documentation for Arrays and i so use to making arrays the way I learned them...
    PHP:
    $cash = ("I have lot of"," cash in my pocket");
    But while reading over the docs , I see a whole new syntax look!

    PHP:
    <?php
    $array 
    = array(
        
    "foo" => "bar",
        
    42    => 24,
        
    "multi" => array(
             
    "dimensional" => array(
                 
    "array" => "foo"
             
    )
        )
    );

    var_dump($array["foo"]);
    var_dump($array[42]);
    var_dump($array["multi"]["dimensional"]["array"]);
    ?>
    As You can see I don't understand thios at all!! What I think it means is

    PHP:
    <?php
    $array 
    = array( //starg of the array
        
    "foo" => "bar"// [0] replacement
        
    42    => 24// replecing [1]
        
    "multi" => array( // Fucking lost!
             
    "dimensional" => array(
                 
    "array" => "foo"
             
    )
        )
    );

    var_dump($array["foo"]); // will display variables in "foo" array section ?
    var_dump($array[42]);
    var_dump($array["multi"]["dimensional"]["array"]);
    ?>
    Halp Meh? <3
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    As a config it would be:
    Code:
    foo: bar
    42: 24
    multi:
       dimensional:
          array: foo
    Maybe that helps
    CrazedMiner likes this.
  3. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    what?
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP arrays are actually like maps in Java. The keys can be string and/or int. "foo" => "bar" is equivalent to a map entry with String key foo and String value bar.

    If strings and ints are used together as keys, ints will be casted into strings.
    thebigsmileXD likes this.

Share This Page

Advertisement