In this tutorials Developer Guidance Cover how to append to array in PHP, Array Push in php and How to add in php.
You should know for PHP array push:
- PHP array_push() is a function used to inserts one or more elements to the end of an array.
- You can add one value, or as many as you like.
- Your added elements will always have numeric keys.
- First time PHP array push used in PHP4
Syntax: PHP array push
The syntax for append to array or array push is array_push(array, value1, value2, …).
array_push() Explained:
PHP an inbuilt function called array_push.. This function push the variable onto the the end of the array. For example :
1 2 3 4 5 |
<?php $z = ['developer','guidance', 'is']; array_push($z, 'best', 'web developer blog'); print_r($z); ?> |
Output:
Go through the below code. You can see an array contains the string keys. Take a look how two new values are added at the end using PHP array push function. For example :
1 2 3 4 5 6 7 8 |
<?php $dg = [ 'developer' => 'guidance', 'web' => 'developer' ]; array_push($dg, 'follow', 'us'); print_r($dg); ?> |
Subscribe Developer Guidance for new updates and tutorials on web development.