Results 1 to 2 of 2

Thread: pushing values in array ??

  1. #1
    Join Date
    May 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default pushing values in array ??

    Hello forums !!
    I would like to push the values in array(without specifying index).
    Can anybody give me the suggestion.
    Note: It should be equivalent to PHP's
    PHP Code:
    $exp_array = array();
    $exp_array[] = "value1";
    $exp_array[] = "value2"
    (without specifying indexes)
    ...........etc

    Thanks in advance to all of you.

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    You can use array_push() available in PHP for doing this. Below mentioned is the example code in PHP Manual

    Code:
    <?php
    $stack = array("orange", "banana");
    array_push($stack, "apple", "raspberry");
    print_r($stack);
    ?>
    he above example will output:
    Code:
    Array
    (
        [0] => orange
        [1] => banana
        [2] => apple
        [3] => raspberry
    )
    A demo and explanation can be found here

    In JavaScript there is a push() associated to the Array object using which you can achieve the same effect

    Code:
    var newArray = new Array(10);
    newArray.push("a","b","c");

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
  •