summaryrefslogtreecommitdiffstats
path: root/arrfuncs.php
blob: 3595b99b7f4eacd1d056c16b2e5cdcf18d198153 (plain)
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hacker's Corner</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h2>Beyond The Basics?</h2>
<p>
shift and unshift chops/prepends the beginning of the array<br />
<?php
    $arr = array("bro", "bro bro", "brotato", "foo");
    print_r($arr);
    echo "<br /><br />\n";

    /* shift a value from an array */
    $a = array_shift($arr);
    echo $a . "<br /><br />\n";

    /* unshift an element, this func returns the element count */
    $c = array_unshift($arr, $a);
    print_r($arr);
    echo "<br /><br />\n";
?>

pop and push<br /> 
<?php
    /* pop a value from an array */
    $a = array_pop($arr);
    echo $a . "<br /><br />\n";

    /* push back an element, this func returns the element count */
    $c = array_push($arr, "foo");
    $c = array_push($arr, "bar");
    print_r($arr);
?>
</p>
</body>
</html>