1$myArr = [1, 2, 3, 4];
2
3array_push($myArr, 5, 8);
4print_r($myArr); // [1, 2, 3, 4, 5, 8]
5
6$myArr[] = -1;
7print_r($myArr); // [1, 2, 3, 4, 5, 8, -1]
1$fruits = ["apple", "banana"];
2// array_push() function inserts one or more elements to the end of an array
3array_push($fruits, "orange");
4
5// If you use array_push() to add one element to the array, it's better to use
6// $fruits[] = because in that way there is no overhead of calling a function.
7$fruits[] = "orange";
8
9// output: Array ( [0] => apple [1] => banana [2] => orange )
1
2<?php
3$cesta = array("laranja", "morango");
4array_push($cesta, "melancia", "batata");
5print_r($cesta);
6?>
7
8
1
2<?php
3$stack = array("orange", "banana");
4array_push($stack, "apple", "raspberry");
5?>
6
7
1$cart = array();
2$cart[] = 13;
3$cart[] = 14;
4// etc
5
6//Above is correct. but below one is for further understanding
7$cart = array();
8for($i=0;$i<=5;$i++){
9 $cart[] = $i;
10}
11echo "<pre>";
12print_r($cart);
13echo "</pre>";
1$cart = array();
2$cart[] = 13;
3$cart[] = 14;
4// etc
5
6//Above is correct. but below one is for further understanding
7$cart = array();
8for($i=0;$i<=5;$i++){
9 $cart[] = $i;
10}
11echo "<pre>";
12print_r($cart);
13echo "</pre>";
14