Hi there...
I'm loving arrays!

I have a set of checkboxes in the array like such:

<td><input type="checkbox" name="CheckedArray[<?php echo $ID?>]"></td>

If I print_r my array I get: Array ( [6] => on [3] => on [7] => )
which is correct.

then(check against a file):

 if($CheckedArray[$anotherID] !="") $Array[] =$anotherID;

and print_r gives: Array ( [0] => 6 [1] => 3 )

and heres where it goes wrong
if $Array already has values I want to add the new ones...

$Array = $Array + $Array;

gives Fatal error: Unsupported operand types

but
http://www.php.net/manual/en/language.operators.array.php
seems to suggest that I should be able to do this
And I've tried playing round like:
setting

$a = $Array; 

before $Array is populated again then

$b = $Array; 

(with new values)
and

$Array = $a + $b;

but no dice....

any ideas please??
thanks
Beth

    Just using the empty brackets will append new entries.

    $Array[] = $id1;
    $Array[] = $id2;
    $Array[] = $id3;

    Gives an array with three entries;

      Thanks for your reply.
      I want to use the + as hmmm maybe I oversimplified earlier...
      I check that $Array has values and then assign to a Global array...
      so I'm wanting to update the Global Array....

      So I think I'll just take out the middle step and go from $CheckedArray to Global$Array without $Array in the middle...

      </end thinking out loud!>

      Thanks again
      Beth

        I wish that had worked... but trying to assign directly to the GlobalArray gave the following:

        if ($CheckedArray[$anotherID] !="") $_SESSION['GlobalArray'][] = $anotherID;

        Fatal error: [] operator not supported for strings

        now $anotherID = int4...

        any ideas??

        Thanks
        Beth

          I'm guessing here.

          This works
          $SERVER['global_array'][] = 1;
          $
          SERVER['global_array'][] = 2;
          print_r($_SERVER['global_array']);

          I don't do sessions much. You might need to make sure your global array is initialized as an array before registering it. From the error message, it seems like php think's it's a string.

            sorry didn't mean to post new thread.. theres no 'opps I take it back option' here :-(

            It does seem as those $_SESSION['GlobalArray'] is seen as a string... but I don't know how to intialise it without adding data.. and I don't want to add data that I'll have to deal with later...
            any ideas?

            my other option seems to be to go back to $Array + $Array... but I still don't know why I can't do that?

            Thanks for your help...
            Beth

              You can create an empty array with
              $data = array();

                Thank you both.
                Push_array was more what I was after to add to the array rather than overwrite...

                but it wouldn't work till I'd intialised the array!

                now to get the next step working!!

                Thanks again :-)
                Beth

                  Write a Reply...