SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Basic Question.....I think?

    Hi,

    I'm relatively new to php been doing it a couple of weeks and i have a what i think is a basic question. Here is my code.

    PHP Code:
    <?php
            $max 
    $_POST["max"];
            
    $newArray = array();
            
    $print FALSE;
            for(
    $i=0;$i<$max;$i++)
            {
            
    $originalArray[i] = $_POST["text$i"];
               
                    if(
    $i == $max && $print == FALSE)
                    {
                            
    $newArray[0] = $originalArray[i];
                            
    //echo "     $newArray[0] <br>";
                    
    }
                    if(
    $i == $max && $print == FALSE)
                    {
                            
    $newArray[1] = $originalArray[i];
                            
    //echo "     $newArray[1] <br>";
                    
    }
                    if(
    $i == $max && $print == FALSE)
                    {
                            
    $newArray[2] = $originalArray[i];
                            
    //echo "     $newArray[2] <br>";
                            
    $print TRUE;
                            
    $i 0;
                    }
                           
                    if(
    $i $max && $print == FALSE)
                    {
                            for(
    $k=$i+3;$k<$i+4;$k++)
                            {
                        
    $newArray[k]=$originalArray[i];
                                    
    //echo "    $newArray[k] ";
            
    }
            }
              
            
    /*why doesn't this loop know what's inside newArray is when it is declared and assigned above*/
            
    if($print == TRUE)
            {
                    echo 
    "$i = $newArray[i]";                     
                    if(((
    $i+1) % 3) == 0)
                    {
                            echo 
    "<br>";
                    }
             }      
    }
    ?>

    and the output is

    Code:
     0 = 1 = 2 =
    3 = 4 = 5 =
    6 = 7 = 8 =
    9 = 10 = 11 =
    12 = 13 = 14 =
    15 = 16 = 17 =
    18 = 19 = 20 =
    21 = 22 = 23 =
    24 = 25 = 26 =
    why doesnt the last loop know what's inside $newArray[] is when it is declared and assigned above.

    thanks

    Greg

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo $i ' = ' $newArray[$i]; 
    You had an error.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply.

    Now it only seems to print out the first 3 items in the array.

    The array is filled above - i've checked and it is definitely filled.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •