Skip to content

casting_operators.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
<html>
 <head><title>Type Casting</title></head>
 <body bgcolor="aqua">
  <font face="verdana" size="+1">
  <?php
    $string = "500";
    $number = (int) $string;
    echo "The value in \$string has been cast to an int: "
        , $number, "<br />";
  ?>
  <hr>
  <?php
    $total_seconds = 1132; //Total running time in seconds
    echo($total_seconds / 60);
    $minutes = (int)($total_seconds / 60); /* Result of expression
                                              is cast to an integer */
    $seconds_left = $total_seconds % 60; // Modulus returns
                                         // seconds left
    print "You ran for $minutes minutes and $seconds_left
           seconds\n.";
  ?>
  <hr>
  <?php
    $total = 5;
    $non_float_total = (int) 5;
    echo $non_float_total + 2.3;
    $total = (float) $total;
    echo "\$total has been cast to float: ", $total + 2.3, "<br />";
    if( "2"> "100 dogs") {print "true";}
  ?>
 </body>
</html>