ネストされた配列のキーに値が存在する限り、チェックする関数を作成するにはどうすればよいtrue
ですか?
例えば、
$input = array(
"path" => null,
"type" => array (
"post" => null,
"page" => null
),
"title" => null,
"category" => array(
"image" => "on"
)
);
function validate_array($input = array())
{
# Loop the array.
foreach($input as $key => $value)
{
if($value && !is_array($value)) return true;
elseif(is_array($value))
{
validate_array($value);
}
elseif($value)
{
return true;
}
}
# Return the result.
return false;
}
var_dump(validate_array($input)); // return bool(false)
true
ネストされた配列の 1 つ (カテゴリ)にオンの値があるため、返されるはずです。