xxxxxxxxxx
$arr = array(
"name" => "jonh",
"Mob" => "588555",
"Email" => "jonh143@gmail.com"
);
$arr['Country'] = "United State";
xxxxxxxxxx
// for php 5.4+
$data += [$key => $value];
// for php 5.4-
$data += array($key => $value);
xxxxxxxxxx
<?php
// Insert "blue" and "yellow" to the end of an array:
$a=array("red","green");
array_push($a,"blue","yellow");
print_r($a);
?>
xxxxxxxxxx
$a1=['aa'=>'123' , 'bb'=>'454'];
$a1 = array_merge( $a1 , ['a'=>1,'b'=>2] ) ;
xxxxxxxxxx
$data['one'] = 1;
$data += [ "two" => 2 ];
$data += [ "three" => 3 ];
$data += [ "four" => 4 ];
//You can also, of course, append more than one element at once...
$data['one'] = 1;
$data += [ "two" => 2, "three" => 3 ];
$data += [ "four" => 4 ];
xxxxxxxxxx
$a = array('foo' => 'bar'); // when you create
$a['Title'] = 'blah'; // later
xxxxxxxxxx
$myArr = [1, 2, 3, 4];
array_push($myArr, 5, 8);
print_r($myArr); // [1, 2, 3, 4, 5, 8]
$myArr[] = -1;
print_r($myArr); // [1, 2, 3, 4, 5, 8, -1]
xxxxxxxxxx
$cart = array();
$cart[] = 13;
$cart[] = 14;
// etc
//Above is correct. but below one is for further understanding
$cart = array();
for($i=0;$i<=5;$i++){
$cart[] = $i;
}
echo "<pre>";
print_r($cart);
echo "</pre>";
xxxxxxxxxx
<?php
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
?>
xxxxxxxxxx
$cart = array();
$cart[] = 13;
$cart[] = 14;
// etc
//Above is correct. but below one is for further understanding
$cart = array();
for($i=0;$i<=5;$i++){
$cart[] = $i;
}
echo "<pre>";
print_r($cart);
echo "</pre>";