PHP: Array of Array's

Discussion in 'Software' started by DaRkKn1qHt, Jan 31, 2005.

  1. DaRkKn1qHt

    DaRkKn1qHt Private First Class

    In my current project I wish to have an array filled with arrays. The way I comprehend the objective is to have a master array labeled $Master and fill this with minor arrays labeled $Minor. Then later extract the $Minor from the $Major and list the variables stored within. The code I created to do this does not perform to the design I wish to have.

    PHP:
    $Major= array();
    $Minor= array();
    for (
    $outerloop=0$outerloop<3$outerloop++)
    {
      for (
    $loop=0$loop<3$loop++)
      {
        
    $Minor[$loop]= $name;
      }
      
    $Major[$outerloop]=$Minor;
    }
    ......

    $amount=count($Major);
    for (
    $loop=0$loop<=$amount;$loop++)
    {
      
    $Minor=$Major[$loop];
      echo 
    $Minor[0];
      echo 
    $Minor[1];
      echo 
    $Minor[3];
    }

    Now my problem is that when i execute this code if the $names are("Phil","Bill","Adam") The output will only be "Phi". So as you can see this is not the response I want. Plz help
     
  2. Wookie

    Wookie Sergeant Major

    Im not to sure what your trying to do, but echo $Minor[3]; does NOT exist because you did while < 3 not <= 3, so your loop is gonna go, 0, 1, 2


    Make that echo $Minor[2]; and you will get a few more values to print.
     
  3. DaRkKn1qHt

    DaRkKn1qHt Private First Class

    This is just an example it is not exactly like what I am working on. All I want to do is find out how to store 1 array, full of information, into another array. Then I will worry about figuring out how to retrieve it.
    Is the proper form:
    Ex.)
    $Major[$outerloop]=$Minor;
    OR
    $Major[$outerloop]=$Minor[];
    OR something totally else. Should I use push and pop? and again with brackets without. Somehow my program is not storing the array, of information, into the other array, it is only storing partial information.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds