-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path22.10 Array_Merge & Array_Combine.php
More file actions
54 lines (36 loc) · 1.19 KB
/
22.10 Array_Merge & Array_Combine.php
File metadata and controls
54 lines (36 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
// Array_Merge()
// index or Associative Array
// The array_merge() function merge one or more arrays into one array.
// index array Array_merge()
$fruit = ["orange", "banana", "grapes"];
$veggie = ['carrot', 'pea'];
$newArray = array_merge($fruit, $veggie);
echo "<pre>";
print_r($newArray);
echo "</pre>";
// **********************************************************************************************************
// array_merge_recursive()
//
$fruit1 = ['a' => "orange", 'b' => "banana", 'c' => "grapes"];
$veggie1 = [
'b' => ['color' => ['red', 'blue', 'green']],
'e' => 'pea',
55,
68
];
$newArray1 = array_merge_recursive($fruit1, $veggie1);
echo "<pre>";
print_r($newArray1);
echo "</pre>";
// **********************************************************************************************************
// Array_Combine()
// index Array
// The array_combine() function creates an array by using the elements from one "keys" array and one "values" array.
// arrays must have equal number of elements!
$name = array("ram", "mohan", "dalveer");
$age = array("35", "37", "43");
$newArray3 = array_combine($name, $age);
echo "<pre>";
print_r($newArray3);
echo "</pre>";