-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrays.php
69 lines (44 loc) · 1.24 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
60
61
62
63
64
65
66
67
68
<?php
$num = array(1,2,3,4,5,6,7,8);
echo $num[3];
for( $i= 0 ;$i<7;$i++)
{
echo $num[$i].'</br>';
}
echo"we can also show the array for development perpose like this:</br>";
print_r($num);
echo "</br> But it won't print out with the regulra print statment</br>";
echo $num;
echo "If i want to add an item to the array I have to put arraynamr[] = value";
echo "In Php 5.4 and aboveadd new array syntax</br>";
$newarray = [2,3,4,5,6];
print_r($newarray);
?>
</br>
<h1>Assosiative array</h1>
<?php
$AssosiativeArray = ['key1'=>'value1','key2'=>'value2','key3'=>'value3'];
print_r($AssosiativeArray);
echo '</br>'. $AssosiativeArray['key1'];
?>
</br>
<h1>Array functions</h1>
count:<?php echo count($AssosiativeArray);?></br>
Max value : <?php echo max($newarray);?></br>
Min value : <?php echo min($newarray);?></br>
<strong>Sorting arrays</strong>
</br>
<?php
sort($AssosiativeArray);
print_r($AssosiativeArray);
echo "</br> Soritng desending";
rsort($AssosiativeArray);
print_r($AssosiativeArray);
?>
</br>
<strong> Breaking the arrrays and trurn them into the long string</strong></br>
<?php
$longarraystring = implode('****', $AssosiativeArray);
echo $longarraystring;
echo "</br> Opposite of implode is explode. It gets a string and "
?>