-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorderarray.php
More file actions
59 lines (46 loc) · 1.27 KB
/
orderarray.php
File metadata and controls
59 lines (46 loc) · 1.27 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
<?php
$array = array("apple", "banana", "cherry", "date", "elderberry");
echo "Original Array: ";
print_r($array);
echo "<br>";
echo "Accessing the second element: ". $array[1]. "<br><br>";
$array[5] = "fig";
echo "After adding a new element: ";
print_r($array);
echo "<br>";
$array[1] = "blueberry";
echo "After changing the second element: ";
print_r($array);
echo "<br><br>";
array_push($array, "grape", "honeydew");
echo "After pushing two new elements: ";
print_r($array);
echo "<br>";
$lastElement = array_pop($array);
echo "Popped element: ". $lastElement. "<br>";
echo "After popping an element: ";
print_r($array);
echo "<br><br>";
$firstElement = array_shift($array);
echo "Shifted element: ". $firstElement. "<br>";
echo "After shifting an element: ";
print_r($array);
echo "<br>";
array_unshift($array, "apricot", "avocado");
echo "After unshifting two new elements: ";
print_r($array);
echo "<br><br>";
unset($array[3]);
echo "After unsetting the fourth element: ";
print_r($array);
echo "<br>";
array_splice($array, 2, 2, array("kiwi", "lemon"));
echo "After splicing two new elements: ";
print_r($array);
echo "<br><br>";
$nestedArray = array("orange", "pineapple", "quince");
$array[] = $nestedArray;
echo "After adding a nested array: ";
print_r($array);
echo "<br>";
?>