PHP Scripts Development » General Web Development Forum

php adding to array

(9 posts)

Tags:

Great offers not only for geeks!


  1. sakefox

    sakefox
    Member

    I didn't see this in the manual so i might have missed it, but is there a easy way to add to a already existing array.

    example:
    have this array

    Array
    (
        [0] => 1
        [1] => 1
    )

    but now want to add
    [3] => 1
    to it. is there a easy way to do this or does it have to be broke down and recreated?

    Posted 3 months ago #
  2. You mean this?

    $somearray = array('0'=>'hello', '1'=>'world');
    $somearray[3] = 'cool';
    Posted 3 months ago #
  3. sakefox

    sakefox
    Member

    I guess i left a lot out in this, that's what i get for posting when i get up lol

    Here is what i am trying to do:

    have a array that has X amount of info in it (amount is different for each item). but need to be able to add more items to that array later on. The array is going to be stored in a mysql table, but i need the ability to add or remove items to the array.

    the only way i had thought about doing it was doing a foreach on the original array stored in the database and the again on the array created from the form and then combining it to one array, but thought there had to be a much easier way

    Posted 3 months ago #
  4. Yeah right, in the beginning are very scary, but if you know them a little they are very powerful ;)

    Do you need a special array index system?

    do you use serialize to store the array in you mysql database?

    Posted 3 months ago #
  5. sakefox

    sakefox
    Member

    yeah i use serialize to put them in the the database.

    yeah arrays are a little intimidating at first, but they get easier. its just trying to add more or take stuff out of the array is where i am having a small snag on

    Posted 3 months ago #
  6. A good training is building arrays with multiple array (think about parsing XML)

    Posted 3 months ago #
  7. sakefox

    sakefox
    Member

    you have a link or info on that?

    if i'm going to learn it might as well learn it correctly then off bad way hehe

    Posted 3 months ago #
  8. ... check the array page from the manual

    <?php
    $fruits = array (
       "fruits"  => array("a" => "orange", "b" => "banana", "c" => "apple"),
       "numbers" => array(1, 2, 3, 4, 5, 6),
       "holes"   => array("first", 5 => "second", "third")
    );
    ?>
    Posted 3 months ago #
  9. sakefox

    sakefox
    Member

    bah, i must have over looked that thanks heh

    Posted 3 months ago #

RSS feed for this topic

Reply

You must log in to post.