forked from assembler-institute/php-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays.php
59 lines (40 loc) · 1.18 KB
/
arrays.php
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
//Define a simple array composed of text strings
$arrayString = ['Simple', 'array', '.'];
var_dump($arrayString);
echo "<br>";
//Define a simple array consisting of whole numbers and decimal numbers.
$arrayNum = [7, 7.2, 9];
var_dump($arrayNum);
echo "<br>";
//Define a multidimensional array.
$arrayMultidim = [
"Multidimensional",
["a", "b", "c"],
[7, 7.2, 9]
];
var_dump($arrayMultidim);
echo "<br>";
//Execute the function that allows to obtain the length of an array.
$arrayLength = count($arrayString);
echo $arrayLength;
echo "<br>";
//Execute the function that allows to obtain the combination of two arrays.
$arrayCombi = array_merge($arrayString, $arrayNum);
print_r(array_merge($arrayString, $arrayNum));
echo "<br>";
var_dump($arrayCombi);
echo "<br>";
//Execute the function that once is given an array return the last element of it.
$arrayLastElement = end($arrayNum);
echo $arrayLastElement;
echo "<br>";
//Execute the function that once is given an array add a new element to the array in question.
$arrayAddElement = array_push($arrayNum, 12, 15.3);
print_r($arrayNum);
echo "<br>";
var_dump($arrayNum);
echo "<br>";
echo $arrayAddElement;
echo "<br>";
?>