当前位置: 首页>>代码示例>>PHP>>正文


PHP divide函数代码示例

本文整理汇总了PHP中divide函数的典型用法代码示例。如果您正苦于以下问题:PHP divide函数的具体用法?PHP divide怎么用?PHP divide使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了divide函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: add

<?php

function add($a, $b)
{
    return $a + $b;
}
function subtract($a, $b)
{
    return $a - $b;
}
function multiply($a, $b)
{
    return $a * $b;
    // Add code here
}
function divide($a, $b)
{
    return $a / $b;
}
// Add code to test your functions here
echo add(4, 5);
echo subtract(18, 9);
echo multiply(3, 3);
echo divide(18, 3);
开发者ID:pswantner,项目名称:Codeup-Web-Excercises,代码行数:24,代码来源:arithmetic.php

示例2: __call

 public function __call($method, $parameters)
 {
     if (!defined('static::factory')) {
         throw new UndefinedConstException('[const factory] is required to use the [Call Factory Method Ability]!');
     }
     $originMethodName = $method;
     $method = strtolower($method);
     $calledClass = get_called_class();
     if (!isset(static::factory['methods'][$method])) {
         Support::classMethod($calledClass, $originMethodName);
     }
     $class = static::factory['methods'][$method];
     $factory = static::factory['class'] ?? NULL;
     if ($factory !== NULL) {
         return $factory::class($class)->{$method}(...$parameters);
     } else {
         $classEx = explode('::', $class);
         $class = $classEx[0] ?? NULL;
         $method = $classEx[1] ?? NULL;
         $isThis = NULL;
         if (stristr($method, ':this')) {
             $method = str_replace(':this', NULL, $method);
             $isThis = 'this';
         }
         $namespace = str_ireplace(divide($calledClass, '\\', -1), NULL, $calledClass);
         $return = uselib($namespace . $class)->{$method}(...$parameters);
         if ($isThis === 'this') {
             return $this;
         }
         return $return;
     }
 }
开发者ID:znframework,项目名称:znframework,代码行数:32,代码来源:MagicFactory.php

示例3: testTraverseFailureForArrayOfInt

 public function testTraverseFailureForArrayOfInt()
 {
     $dividend = 12;
     $divisors = [2, 0, 6];
     $intsArray = new AssociativeArray($divisors);
     $instance = Either::left('');
     $eitherResults = $intsArray->traverse(function ($i) use($dividend) {
         return divide($dividend, $i);
     }, $instance);
     $expected = Either::left('Division by zero!');
     $this->assertEquals($expected, $eitherResults);
 }
开发者ID:tmciver,项目名称:functional-php,代码行数:12,代码来源:ArrayTest.php

示例4: class

 public static function class(string $class)
 {
     $namespace = NULL;
     if (defined('static::namespace')) {
         $namespace = suffix(static::namespace, '\\');
     } else {
         $calledClass = get_called_class();
         $namespace = str_ireplace(divide($calledClass, '\\', -1), NULL, $calledClass);
     }
     $class = $namespace . $class;
     return uselib($class);
 }
开发者ID:znframework,项目名称:znframework,代码行数:12,代码来源:Factory.php

示例5: ipv4

function ipv4() : string
{
    if (isset($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = divide($_SERVER['HTTP_X_FORWARDED_FOR'], ',');
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    if ($ip === '::1') {
        $ip = '127.0.0.1';
    }
    return $ip;
}
开发者ID:znframework,项目名称:znframework,代码行数:14,代码来源:Server.php

示例6: __construct

 public function __construct()
 {
     if (defined('static::connection')) {
         Config::set('Database', 'database', static::connection);
     }
     if (defined('static::table')) {
         $grandTable = static::table;
     } else {
         $grandTable = divide(str_ireplace([INTERNAL_ACCESS, 'Grand'], '', get_called_class()), '\\', -1);
     }
     $this->grandTable = strtolower($grandTable);
     $tables = DBTool::listTables();
     if (!in_array($this->grandTable, Arrays::map('strtolower', $tables))) {
         throw new Exception(lang('Database', 'tableNotExistsError', 'Grand: ' . $grandTable));
     }
 }
开发者ID:znframework,项目名称:znframework,代码行数:16,代码来源:GrandModel.php

示例7: use

 public function use(string $randomPageVariable, array $randomDataVariable = NULL, bool $randomObGetContentsVariable = false)
 {
     if (!empty(Properties::$parameters['usable'])) {
         $randomObGetContentsVariable = Properties::$parameters['usable'];
     }
     if (!empty(Properties::$parameters['data'])) {
         $randomDataVariable = Properties::$parameters['data'];
     }
     Properties::$parameters = [];
     $eol = EOL;
     $randomPageVariableExtension = extension($randomPageVariable);
     $randomPageVariableBaseUrl = baseUrl($randomPageVariable);
     $return = '';
     if (!is_file($randomPageVariable)) {
         throw new InvalidArgumentException('Error', 'fileParameter', '1.($randomPageVariable)');
     }
     if ($randomPageVariableExtension === 'js') {
         $return = '<script type="text/javascript" src="' . $randomPageVariableBaseUrl . '"></script>' . $eol;
     } elseif ($randomPageVariableExtension === 'css') {
         $return = '<link href="' . $randomPageVariableBaseUrl . '" rel="stylesheet" type="text/css" />' . $eol;
     } elseif (stristr('svg|woff|otf|ttf|' . implode('|', Config::get('ViewObjects', 'font')['differentFontExtensions']), $randomPageVariableExtension)) {
         $return = '<style type="text/css">@font-face{font-family:"' . divide(removeExtension($randomPageVariable), "/", -1) . '"; src:url("' . $randomPageVariableBaseUrl . '") format("truetype")}</style>' . $eol;
     } elseif ($randomPageVariableExtension === 'eot') {
         $return = '<style type="text/css"><!--[if IE]>@font-face{font-family:"' . divide(removeExtension($randomPageVariable), "/", -1) . '"; src:url("' . $randomPageVariableBaseUrl . '") format("truetype")}<![endif]--></style>' . $eol;
     } else {
         $randomPageVariable = suffix($randomPageVariable, '.php');
         if (is_file($randomPageVariable)) {
             if (is_array($randomDataVariable)) {
                 extract($randomDataVariable, EXTR_OVERWRITE, 'zn');
             }
             if ($randomObGetContentsVariable === false) {
                 require $randomPageVariable;
             } else {
                 ob_start();
                 require $randomPageVariable;
                 $randomSomethingFileContent = ob_get_contents();
                 ob_end_clean();
                 return $randomSomethingFileContent;
             }
         }
     }
     if ($randomObGetContentsVariable === false) {
         echo $return;
     } else {
         return $return;
     }
 }
开发者ID:znframework,项目名称:znframework,代码行数:47,代码来源:Something.php

示例8: divide

/**
 * @param array $arr
 *
 * @return array
 */
function divide(array $arr)
{
    if (1 === count($arr)) {
        return $arr;
    }
    $left = $right = [];
    $middle = round(count($arr) / 2);
    for ($i = 0; $i < $middle; ++$i) {
        $left[] = $arr[$i];
    }
    for ($i = $middle; $i < count($arr); ++$i) {
        $right[] = $arr[$i];
    }
    $left = divide($left);
    $right = divide($right);
    return conquer($left, $right);
}
开发者ID:biroa,项目名称:php_algorithms,代码行数:22,代码来源:mergesort.php

示例9: mathOperation

function mathOperation($arg1, $arg2, $operation)
{
    switch ($operation) {
        case 'add':
            echo adding($arg1, $arg2);
            break;
        case 'substract':
            echo substracting($arg1, $arg2);
            break;
        case 'multiply':
            echo multiply($arg1, $arg2);
            break;
        case 'divide':
            echo divide($arg1, $arg2);
            break;
        default:
            echo "Вы не корректно определили параметры!";
            break;
    }
}
开发者ID:GonikDaniel,项目名称:php_study_project,代码行数:20,代码来源:item4.php

示例10: divide

}
function divide($a, $b)
{
    if ($b == 0) {
        return "Error: You cannot divide by 0\n";
    } elseif (is_numeric($a) && is_numeric($b)) {
        return $a / $b;
    } else {
        return errorMessage($a, $b);
    }
}
function modulus($a, $b)
{
    if (b == 0) {
        return "Error: You cannot divide by 0\n";
    } elseif (is_numeric($a) && is_numeric($b)) {
        return $a % $b;
    } else {
        return errorMessage($a, $b);
    }
}
function errorMessage($a, $b)
{
    return 'ERROR: Please input only numbers for $a is ' . $a . ' and $b is ' . $b . PHP_EOL;
}
// Add code to test your functions here
echo add($a, $b) . PHP_EOL;
echo subtract($a, $b) . PHP_EOL;
echo multiply($a, $b) . PHP_EOL;
echo divide($a, 0) . PHP_EOL;
echo modulus($a, $b) . PHP_EOL;
开发者ID:sshaikh210,项目名称:Codeup-Web-Exercises,代码行数:31,代码来源:arithmetic.php

示例11:

    echo 'OK<br>';
} else {
    echo 'erro<br>';
}
if (multi(5, 2) == 5 * 2) {
    echo 'OK<br>';
} else {
    echo 'erro<br>';
}
if (divide(5, 2) == 5 / 2) {
    echo 'OK<br>';
} else {
    echo 'erro<br>';
}
if (some(5, multi(2, 3)) == 5 + 2 * 3) {
    echo 'OK<br>';
} else {
    echo 'erro<br>';
}
if (subtrair(8, some(3, 5)) == 8 - (3 + 5)) {
    echo 'OK<br>';
} else {
    echo 'erro<br>';
}
if (some(divide(9, 3), multi(4, 2)) == 9 / 3 + 4 * 2) {
    echo 'OK<br>';
} else {
    echo 'erro<br>';
}
?>
</pre>
开发者ID:alexdesigner,项目名称:calc-2,代码行数:31,代码来源:calc_teste.php

示例12: use

 public function use(...$fonts)
 {
     $eol = EOL;
     $str = "<style type='text/css'>" . $eol;
     $args = $this->_parameters($fonts, 'fonts');
     $lastParam = $args->lastParam;
     $arguments = $args->arguments;
     $links = $args->cdnLinks;
     foreach ($arguments as $font) {
         if (is_array($font)) {
             $font = '';
         }
         $f = divide($font, "/", -1);
         // SVG IE VE MOZILLA DESTEKLEMIYOR
         $fontFile = FONTS_DIR . $font;
         if (!is_file($fontFile)) {
             $fontFile = EXTERNAL_FONTS_DIR . $font;
         }
         $baseUrl = baseUrl($fontFile);
         if (extension($fontFile)) {
             if (is_file($fontFile)) {
                 $strEx = Import::something($fontFile, '', true);
                 break;
             }
         }
         if (is_file($fontFile . ".svg")) {
             $str .= '@font-face{font-family:"' . $f . '"; src:url("' . $baseUrl . '.svg") format("truetype")}' . $eol;
         }
         if (is_file($fontFile . ".woff")) {
             $str .= '@font-face{font-family:"' . $f . '"; src:url("' . $baseUrl . '.woff") format("truetype")}' . $eol;
         }
         // OTF IE VE CHROME DESTEKLEMIYOR
         if (is_file($fontFile . ".otf")) {
             $str .= '@font-face{font-family:"' . $f . '"; src:url("' . $baseUrl . '.otf") format("truetype")}' . $eol;
         }
         // TTF IE DESTEKLEMIYOR
         if (is_file($fontFile . ".ttf")) {
             $str .= '@font-face{font-family:"' . $f . '"; src:url("' . $baseUrl . '.ttf") format("truetype")}' . $eol;
         }
         // CND ENTEGRASYON
         $cndFont = isset($links[strtolower($font)]) ? $links[strtolower($font)] : NULL;
         if (!empty($cndFont)) {
             $str .= '@font-face{font-family:"' . divide(removeExtension($cndFont), "/", -1) . '"; src:url("' . $cndFont . '") format("truetype")}' . $eol;
         }
         // FARKLI FONTLAR
         $differentSet = Config::get('ViewObjects', 'font')['differentFontExtensions'];
         if (!empty($differentSet)) {
             foreach ($differentSet as $of) {
                 if (is_file($fontFile . prefix($of, '.'))) {
                     $str .= '@font-face{font-family:"' . $f . '"; src:url("' . $baseUrl . prefix($of, '.') . '") format("truetype")}' . $eol;
                 }
             }
         }
         // EOT IE DESTEKLIYOR
         if (is_file($fontFile . ".eot")) {
             $str .= '<!--[if IE]>';
             $str .= '@font-face{font-family:"' . $f . '"; src:url("' . $baseUrl . '.eot") format("truetype")}';
             $str .= '<![endif]-->';
             $str .= $eol;
         }
     }
     $str .= '</style>' . $eol;
     if (isset($strEx)) {
         $str = $strEx;
     }
     if (!empty($str)) {
         if ($lastParam === true) {
             return $str;
         } else {
             echo $str;
         }
     } else {
         return false;
     }
 }
开发者ID:znframework,项目名称:znframework,代码行数:75,代码来源:Font.php

示例13: error_reporting

<?php

error_reporting(E_ALL);
// set error reporting on
function divide($numerator, $denominator)
{
    return $numerator / $denominator;
}
echo divide(1, 2) . '<br />' . PHP_EOL;
// 0.5
echo divide(1, 0) . '<br />' . PHP_EOL;
// "Warning: Division by zero"
echo @divide(1, 0) . '<br />' . PHP_EOL;
// (suppressed)
echo divide(1, 2) . '<br />' . PHP_EOL;
// 0.5
开发者ID:Aeprox,项目名称:ws1-sws-course-materials,代码行数:16,代码来源:errors1.php

示例14: __call

 public function __call($method, $param)
 {
     die(getErrorMessage('Error', 'undefinedFunction', divide(str_ireplace(INTERNAL_ACCESS, '', get_called_class()), '\\', -1) . "::{$method}()"));
 }
开发者ID:znframework,项目名称:znframework,代码行数:4,代码来源:CallController.php

示例15: modulus

        } else {
            echo "ERROR: Cannot divide by 0\n";
        }
    }
}
function modulus($a, $b)
{
    $error = errorCheck($a, $b);
    if ($error) {
        if ($a != 0 && $b != 0) {
            return $a % $b;
        } else {
            echo "ERROR: Cannot divide by 0\n";
        }
    }
}
function errorCheck($a, $b)
{
    if (!is_numeric($a) || !is_numeric($b)) {
        echo "ERROR: Both arguments must be numbers\n";
        return false;
    } else {
        return true;
    }
}
// Add code to test your functions here
echo add(10, 2) . PHP_EOL;
echo subtract(10, 2) . PHP_EOL;
echo multiply(10, 2) . PHP_EOL;
echo divide(10, 2) . PHP_EOL;
echo modulus(10, 2) . PHP_EOL;
开发者ID:pascalallen,项目名称:Codeup_Exercises,代码行数:31,代码来源:arithmetic.php


注:本文中的divide函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。