summaryrefslogtreecommitdiffstats
path: root/datatypes.php
blob: 53e8678578738c3e096940cb1ed28abcba21a6e7 (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
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
<!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>
<h1>Please Don't Fear!</h1>
<b>Sandbox:</b> Let's Roll!<br />
<p>
<?php
    error_reporting(E_ALL | E_STRICT);
    ini_set("display_errors", 1);

    $pi = 3.14159;
    echo "Pi = " . $pi . "<br />";

    $hellomsg = "Hello Kyle, world is good.<br />";
    /* note: single quotes would not do in place variable substitution */
    echo "{$hellomsg}"; /* weird, opposite of bash */

    $myarray = array(12, 21, 33, 99, 33, "fox" /* hmm this is nice */, array("bro", "brotato"));
    echo "2nd item in our array is " . $myarray[1] . " " . $myarray[6][1] . ".<br /><br />";

    /* key-value pairs, i like them, dejavu Lua! */
    $keyval = array("name" => "bro", "status" => "amused", "location" => "/dev/null");
    echo "$keyval[name] is $keyval[status]";

    echo "</p><pre>";
    print_r($keyval);
    echo "</pre><br /><p>";

    /* array into a string? seems heck useful */
    $str_from_arr = implode(" ~ ", $keyval); /* 1st param = glue */
    echo "the imploded array is: {$str_from_arr}";
?>

<!-- just easier to type in html :p -->
<br />
Is Pi set?
    <?php
        if (isset($pi)) /* will catch undefined variables */
            echo "Yes" . "<br />";
        else
            echo "No" . "<br />";

        /* how to escape? */
        $var1 = "\"brotato escaped\"";
        echo "escaped: " . $var1 . ", ha it is just like C!". "<br />";

        unset($pi); /* why not just set it to null? we can set it to 0, "0"! and null */
        if (empty($pi))
            echo "Pi has been unset.<br />";
    ?>
<br />
Typecasting, <b>php is very clever!</b><br />
    <?php
        $pi = 3.14159;
        $piphi = $pi + "1.618 i love this number";
        echo "piphi is of type " . gettype($piphi) . " and equals to {$piphi}.<br />";
        settype($piphi, "string"); /* or just typecast, (string) in front ? */

        /* constants */
        define("PI_VAL", 3.14159);
    ?>
</p>
</body>
</html>