ok, hi all,

i have a problem, i want to check all values and keys from $_POST or $_GET files. My checkings criteria are:
1-) the key must be set;
2-) values must not be empty.

Because $_POST and $_GET values is a array i have the following code:

function checkValues($postValues)
    {
        foreach($postValues as $key => $value)
        {
            if(!isset($key) && $value == "")
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }

however if i have athe following www.domain.com/index.php?hello=hello&code=php
it will be valitaded only the first key and value and not the rest.

could someone help me, please

Try this instead

function checkValues($postValues)
    {
        $valid = true;
        foreach($postValues as $key => $value)
        {
            if(!isset($key) || $value == "")
            {
                $valid = false;
            }
        }
        return $valid;
    }

Edit: Noticed that the && should be ||

Thanks very much Ezzaral, it is working now, my fault was the && condition, but the adjustment you did, were also very good, thanks man

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.