Code: Select all
if(isset($_POST['newdishname']) || isset($_POST['newmethod']) || isset($_POST['newpreptime']) || isset($_POST['newcooktime']) || isset($_POST['newvegetarian']) || isset($_POST['newtype']))
{
.....
}Moderator: General Moderators
Code: Select all
if(isset($_POST['newdishname']) || isset($_POST['newmethod']) || isset($_POST['newpreptime']) || isset($_POST['newcooktime']) || isset($_POST['newvegetarian']) || isset($_POST['newtype']))
{
.....
}Code: Select all
$needed_arr = array(
'newdishname',
'newmethod',
'newpreptime',
'newcooktime',
'newvegetarian',
'newtype',
);
$found = false;
foreach ($_POST as $key => $val)
{
if (in_array($key, $needed_arr))
{
$found = true;
continue;
}
}
if ($found)
{
//.....
}Code: Select all
<?php
$checks = array('newdishname', 'newmethod', 'newpreptime', 'newcooktime', 'newvegetarian', 'newtype');
foreach ($checks as $check)
{
if (isset($_POST[$check]))
{
break;
}
}
?>Code: Select all
function issetMultiKeys($source, $keys)
{
foreach ((array)$keys as $key) {
if (!isset($source[$key])) {
return false;
}
}
return true;
}... Learn something new everyday.ole wrote:But you might like to know that isset() will take multiple parameters.
Code: Select all
<?php
/**
* Checks whether an index is set on an array member.
*
* This function will tell whether a particular array var
* is set. It can be used with to check a single string
* array index, a single numeric index or multiple
* indeces of an array. If the optional $requireall
* flag is set to true, it will make sure all members
* of the $required array are set in the $checkthis array.
* @access public
* @param mixed $required The value to search for isset in $checkthis
* @param array $checkthis The array to check the set values if
* @param boolean $requireall Optional flag to force all $required field be set
* @return boolean True if all criteria is met, false otherwise
*/
function is_value_set($required, $checkthis, $requireall = false)
{
// If the index or array to check are empty, return false
if (empty($required) || empty($checkthis))
{
return false;
}
// If the required value to check is a string or number
if (is_string($required) || is_numeric($required))
{
if (isset($checkthis[$required]))
{
return true;
}
return false;
}
// If the required value is an array
if (is_array($required))
{
// Count holder for requireall
$checkcount = 0;
// Loop through the $required value
foreach ($required as $require)
{
if (isset($checkthis[$check]))
{
// If we don't require all and $required is set, return
if (!$requireall)
{
return true;
}
else
{
// Increment the check counter
$checkcount++;
}
}
}
// If we are here then we check if the counts for required match
if ($checkcount == count($required))
{
return true;
}
// The needed criteria were not met, return false
return false;
}
// Again, necessary criteria was not met, retun false
return false;
}
// Set an array of required values
$checks = array('newdishname', 'newmethod', 'newpreptime', 'newcooktime', 'newvegetarian', 'newtype');
// Run them through the function
if (!is_value_set($checks, $_POST))
{
// Error out
}
?>