Skip to main content

How do I build a complex array in PHP?



How can I build an array like this in PHP?





It should have unique keys each of whose corresponding values are arrays, and those arrays have multiple elements for each key.







Array (

42 => Array ( 56, 86, 97 )

51 => Array ( 64, 52 )

)




Comments

  1. $main = array();
    for ($i=0; $i<10; $i++) {
    // $i makes numeric keys
    $main[$i] = array();

    // Or instead, you could make a truly unique key name for each:
    $main[uniqid()] = array(...somevalues...);

    }


    Creates something like:

    Array
    (
    [4f105f361cdd1] => Array
    (
    )

    [4f105f361cf24] => Array
    (
    )

    [4f105f361cf33] => Array
    (
    )

    [4f105f361cf3c] => Array
    (
    )

    [4f105f361cf44] => Array
    (
    )

    )

    ReplyDelete
  2. $arr = array(
    42 => array(56, 86, 97),
    51 => array(64, 52)
    );

    var_dump($arr);

    ReplyDelete
  3. $array = array(42=>array(56,86,97),51=>array(64,52));

    ReplyDelete
  4. $arraytest = array(
    42 => array(56, 86, 97),
    51 => array(64, 52)
    );

    var_dump($arraytest);

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?