PDA

View Full Version : pushing values in array ??



PHPycho
07-03-2007, 11:23 AM
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

$exp_array = array();
$exp_array[] = "value1";
$exp_array[] = "value2";
(without specifying indexes)
...........etc

Thanks in advance to all of you.

codeexploiter
07-03-2007, 12:05 PM
You can use array_push() available in PHP for doing this. Below mentioned is the example code in PHP Manual



<?php
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
print_r($stack);
?>


he above example will output:

Array
(
[0] => orange
[1] => banana
[2] => apple
[3] => raspberry
)

A demo and explanation can be found here (http://au3.php.net/array_push)

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



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