PHP has both integer and float (decimal) number types. These two types can be classified under the generic title numbers.
Valid numbers can be anything like: 8, 258, -37, 89.25, -3.5785, 5.5e2
- Number-type values are never quoted. The numbers added within quotes are strings with numeric values.
PHP supports a maximum integer of around two billion on most platforms (UNIX and Windows). With numbers larger than that, PHP will automatically use a floating-point type.
<?php $x = 5; $y = $x + 3; echo $y; // 8 ?>
<?php $x = 5; $y = $x - 3; echo $y; // 2 ?>
<?php $x = 5; $y = $x * 3; echo $y; // 15 ?>
<?php $x = 5; $y = $x / 3; echo $y; // 1.6666666666667 ?>
<?php $x = 5; $y = $x % 3; echo $y; // 2 ?>
<?php $x = 5; $x++; // Ecivalent with: $x = $x + 1; echo $x; // 6 ?>
<?php $x = 5; $x--; // Ecivalent with: $x = $x - 1; echo $x; // 4 ?>
<?php $x = 5; $y = $x; echo $y; // 5 ?>
<?php $x = 5; $x += 3; // Ecivalent with: $x = $x + 3; echo $x; // 8 ?>
<?php $x = 5; $x -= 3; // Ecivalent with: $x = $x - 3; echo $x; // 2 ?>
<?php $x = 5; $x *= 3; // Ecivalent with: $x = $x * 3; echo $x; // 15 ?>
<?php $x = 5; $x /= 2; // Ecivalent with: $x = $x / 2; echo $x; // 2.5 ?>
<?php $x = 5; $x .= 3; // Ecivalent with: $x = $x . 3; echo $x; // 53 ?>
<?php $x = 5; $x %= 2; // Ecivalent with: $x = $x % 2; echo $x; // 1 ?>
<?php $x = 8 + 3 * 5 -2; echo $x; // 21 (first 3*5 [15], then adds 8 and substract 2 ) $x = (8+3) * (5-2); echo '<br />'. $x; // 33 (first 8+3 [11], then 5-2 [3], then makes the multiplication 11*3 [33] ) ?>
<?php $x = abs(-3.5); // $x = 3.5; $y = abs(-4); // $y = 4; ?>
<?php $x = ceil(3.5); // $x = 4; $y = ceil(-8.5); // $y = -8; ?>
<?php $x = floor(3.5); // $x = 3; $y = floor(-8.5); // $y = -9; ?>
<?php $x = max(5, 88, -12, 78.4); echo $x; // 88 ?>
<?php $x = min(5, 88, -12, 78.4); echo $x; // -12 ?>
<?php $x = 35788; $x = number_format($x); echo $x; // 35,788 $y = 35788.3; $y = number_format($y, 2); echo '<br />'. $y; // 35,788.30 ?>
<?php $x = pow(3, 4); echo $x; // 81 ?>
<?php $x = sqrt(64); echo $x; // 8 ?>
<ul> <li>http://coursesweb.net/html/</li> <li>http://coursesweb.net/css/</li> </ul>
.some_class { display: list-item; }
var obj = { "courses": ["php", "javascript", "ajax"] }; var jsonstr = JSON.stringify(obj); alert(jsonstr); // {"courses":["php","javascript","ajax"]}
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>'; $dochtml = new DOMDocument(); $dochtml->loadHTML($strhtml); $elm = $dochtml->getElementById("dv1"); echo $elm->nodeValue; // CoursesWeb.net