-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13.arrayFunction.php
More file actions
79 lines (67 loc) · 1.71 KB
/
13.arrayFunction.php
File metadata and controls
79 lines (67 loc) · 1.71 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
$cars = array(
"A" => "Volvo",
"B" => "BMW",
"C" => "Toyota",
"D" => "Ford",
"E" => "Audi",
"F" => "Mercedes",
"G" => "Ferrari",
);
echo "<pre>";
print_r($cars);
echo "</pre>";
// is_array() function
if(is_array($cars)){
echo "Yes, \$cars is an array";
}else{
echo "No, \$cars is not an array";
}
// array_search() function
echo "<br>";
echo "The key of Ferrari is: ".array_search("Ferrari", $cars);
echo "<br>";
echo "The key of Ford is: ".array_search("Ford", $cars);
// array_slice() function
$newCars = array_slice($cars, 2);
echo "<pre>";
print_r($newCars);
echo "</pre>";
// array_chunk() function
$newCars = array_chunk($cars, 3);
echo "<pre>";
print_r($newCars);
echo "</pre>";
// array_pop() function
$popedArray = array_pop($cars);
echo "Poped from Array : $popedArray";
// array_push() function
array_push($cars, "Ferrari");
echo "<pre>";
print_r($cars);
echo "</pre>";
// array_keys() function
$keys = array_keys($cars);
echo "<pre>";
print_r($keys);
echo "</pre>";
// array_key_exists() function
var_dump(array_key_exists("D", $cars));
// count() function
echo "Total elements in array: ".count($cars);
// array_values() function
$values = array_values($cars);
echo "<pre>";
print_r($values);
echo "</pre>";
// array_merge() function
$newCars = array(
"H" => "Lamborghini",
"I" => "Bugatti",
"J" => "Koenigsegg",
);
$mergedArray = array_merge($cars, $newCars);
echo "<pre>";
print_r($mergedArray);
echo "</pre>";
?>