AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

PHP array_push() Function


<< Previous Page
PHP tutorial
Next Page >>
PHP tutorial

PHP Tutorial » PHP array_push() Function

What is array push in PHP?

Let's to observe an example in which we insert three car models in a series of other models.

<?php
$autos=array("renault","peugeot","citroen");
array_push($autos,"fiat","alfa romeo","lancia");
print_r($autos);
?>

copy and paste in the editor below, click "Execute" and notice the result

  <?php
$autos=array("renault","peugeot","citroen");
array_push($autos,"fiat","alfa romeo","lancia");
print_r($autos);
?>

 

Functia array push

Defining and using the array_push () function

The array_push () function that inserts one or more elements at the end of a string.

Syntax:

array_push(array, value1, value2, ...)

Technical Details:
Return Value: Returns the new number of elements in the string
PHP Version: from PHP4+
Change log: From PHP7.3 this function can be called with only the array parameter

Related subjects:
What is an array Convert array to string comma PHP syntax

Tags: php push: to array, array into array, associative array, object to array, notification, key value to array, data tu array, value to array, to front of array, to object.

 

PHP array push with key

To make rounded coners for we used CSS Style for .button { border: none; color: white; padding: 10px; text-align: center; text-decoration: none; display: inline-block; font-size: 14px; margin: 8px 4px; cursor: pointer; font-weight: bold;}

Example (this is HTML - PHP editor, change text on this window)
<?php
$autos=array("a"=>"renault"
,"b"=>"peugeot"
,"c"=>"citroen");
array_push($autos,"fiat","alfa romeo"
,"lancia");
print_r($autos);
?>

 

how to push object to an array php

Example (this is HTML - PHP editor, change text on this window)

<?php
$myArr = [11, 12, 13, 14];

array_push($myArr, 15, 18);
print_r($myArr); // [11, 12, 13, 14, 15, 18]

$myArr[] = -11;
print_r($myArr); // [11, 12, 13, 14, 15, 18, -11]
$myArray = array("name" => "my name");
echo json_encode($myArray);
?>

 



php array push: with array, array, to front, key value pair, object, associative, value, if not exists, to first index, multiple values php push: to array, array into array, associative array, object to array, notification, key value to array, data tu array, value to array, to front of array, to object.
PHP array_push() Function - php tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home
PHP Introduction
PHP Install
PHP Syntax
PHP Variables
PHP Echo and Print
PHP Data Types
PHP String Function
PHP Constants
PHP Operator Types
PHP If Else and Elseif
PHP Switch
PHP While Loops
PHP Loop For Do Foreach
PHP Array
Convert Array to String
PHP Function
PHP GET and POST
PHP Date/Time Functions
PHP Login
PHP Delete Element
PHP eregi_replace()
PHP mysql_query()
PHP Errors to Display
PHP Loop For Do Foreach

PHP forms
PHP Form Example
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


jQuery replace...
jQuery replaceClass...
jQuery click ()...
jQuery switchClass()...
jQuery draggable()...
jQuery HTML...
jQuery scroll smooth...
jQuery scroll()...
jQuery stop()...
jQuery animate()...
jQuery SlideToggle()...
jQuery slideDown()...
jQuery slideUp()...
jQuery fadeToggle...
jQuery fadeOut()...
jQuery fadeIn()...
jQuery Effects - hide () and show ()...
jQuery Events...
jQuery Attributes...
jQuery Selectors...