07c04-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 38 行

PHP
38
字号
<?php// Define a Math class that provides static and const members for useclass Math_Extended {    // Declare some constant variables for reference:    // Speed of light (meters per second) (exact)    const C = 299792458;    // Temperature of the Sun (Kelvin) (approximate)    const T_SUN = 5780;        // Radius of the Earth (meters) (approximate)    const R_EARTH = 6378000;        // Now let's declare some static methods - Start with a cube root one:    public static function curt($num) {        return pow($num, 1/3);    }        // A method that will generate the length of a side of a right-angle    // triangle, given the length of one side, and of the hypotenuse    public static function triSide($hypot, $side) {        return sqrt(pow($hypot, 2) - pow($side, 2));    }}// See how long it takes for light to traverse the diameter of the Earth$seconds = (Math_Extended::R_EARTH * 2) / Math_Extended::C;echo "<p>The light would take {$seconds} seconds</p>\n";// Calculate the side of a right triangle.  Use a 1,2,sqrt(3) triangle$side = Math_Extended::triSide(2, sqrt(3));echo "<p>The other side of the triangle is {$side}</p>\n";// Calculate the cube root of 27$root = Math_Extended::curt(27);echo "<p>The cube root of 27 is {$root}</p>\n";?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?