English 中文(简体)
我需要帮助公共卫生和社会福利部,看一看是否愤怒是积极的或消极的[封闭的]。
原标题:I need help in PHP with seeing if an integer is Positive or negative [closed]
  • 时间:2012-05-03 01:09:00
  •  标签:
  • php

奥凯,我做了很多研究,仍然找不到任何工作要做:

书写一种称为<代码>sPositive的PHP功能,该功能包含一个参数,即当愤怒呈阳性时,即为愤怒和回报。 顺便说一句,正数是零。

这就是我需要做的事。 我尝试了不同的事,然而,如果我的人数是正面的还是消极的,我却没什么要试。

感谢你们的帮助!

我是这样说的,但它并不发挥作用:

function isPositive($val = NULL)    // Add default to save php errors if nothing is passed
{
    if ((int)$val)          // type cast for security
    {
            if ($val >= 0)
            {
                    return TRUE;
            }
    }
}

这里是我所尝试的另一项法典,但至今没有发挥作用:

function isPositive($number = NULL)
    if ($number = <0)
        return true;
    else
        return false;
问题回答

我要回答另一个问题:

积极或消极的定义是什么?

积极人数超过零。

否定数字低于零。

因此,你如何比较购买力平价中的两个数字?

是否有经营者这样做?

BONUS:你如何处理零? 它是积极的还是消极的?

function isPositive($number) {
    return is_numeric($number) && ($number >= 0);
}

页: 1 如果你只想为愤怒者工作的话。 让我们看看看你的职能有什么错误:

function isPositive($val = NULL)    // Add default to save php errors if nothing is passed
{
    if ((int)$val)          // type cast for security
    {
            if ($val >= 0)
            {
                    return TRUE;
            }
    }
}
  1. You don t return anything if any of the two clauses fail, there should be a return false; somewhere in there. Your function returns NULL if any of the clauses fail, NULL !== false.
  2. if ((int)$val) is completely wrong. You are checking if the type casting worked or not? That s not useful, what you need to check is if $val is an number or an integer, the simplest way to do that is with is_int, is_float and is_numeric. Check their manual pages for more.
  3. ($val = NULL) is completely unnecessary. You want PHP to throw an error when someone is not using the function correctly.

上文提到的人

$int = (int)-2;

function test( $int ){

    return (bool) ( $int >= 0 );
}

var_dump(test( $int ));
function NegativeOrNot($number)
{    
    if ($number >= 0)
        return true;
    else
        return false;
}

Very simple.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签