Sunday, January 11, 2009

How to put a value to the end of an array - array_push()

You can use array_push() function to pass a value to the end of an array.
array_push(current_array , value )
array_push() accept two basic parameters, first one is the current array you want to push the value. after that you can pass any number of values separated by commas.


<?php

$my_array = array('Me', 'You');
array_push($my_array, 'Others');

print_r($my_array);

/*
Array
(
[0] => Me
[1] => You
[2] => Others
)

*/

?>

No comments:

Post a Comment