#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Location
    Ashburn, Virginia
    Posts
    28
    Rep Power
    0

    Is it possible for array_push( to work on Multidimensional Arrays?


    Hello,

    I was wondering if array_push( had the capabilities to add a value to an existing multidimensional array?

    Here is my code:
    PHP Code:
    array_push($computerparts"Gigabyte K8NXP-SLI"
    This will ofcourse output Gigabyte K8NXP-SLI.

    I try (experimenting) the following:
    array_push($computerparts, "Gigabyte K8NXP-SLI", "299")

    and an echo statement with ($computerparts[1][1]) and it shows G and I.

    Overall, is it possible to accomplish this?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    379
    Rep Power
    25
    Short answer: Yes

    This is the way I tested it.
    PHP Code:
    <?php
    //Is it possible for array_push( to work on Multidimensional Arrays?

    $main = array();

    array_push$main"This is the top array" );

    $second_array = array();

    array_push$second_array"This is a sub array" );

    // now push the second array onto the main array

    array_push($main$second_array);

    // lets print out the $main array
    print_r($main);

    // again called by $main[1][0]
    print "\n" $main[1][0] ."\n";


    // okay so lets push something else onto the sub array
    array_push($main[1], "something else");

    // and print it out again.
    print_r($main);

    // lets call this one
    print "\n"$main[1][1] ."\n";
    paste it and test it.

    xrowNow
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Location
    Ashburn, Virginia
    Posts
    28
    Rep Power
    0
    Is this on PHP 5.x or 4.x becuase it gives me errors when I try to test your code?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    379
    Rep Power
    25
    Originally Posted by Arc4ne
    Is this on PHP 5.x or 4.x becuase it gives me errors when I try to test your code?
    I tested on both php 5.0.3 and php 4.3.6 with no errors.

    what error are you seeing?

IMN logo majestic logo threadwatch logo seochat tools logo