Re: finding if $key has value
| From: | Michael Hall | Date: | Sun, 21 Jul 2002 01:07:29 +0000 |
| Subject: | Re: finding if $key has value | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-108683@lists.php.net to get a copy of this message | ||
Try something like this instead (untested):
while (list($k, $v) = each($data))
{
if (substr($k,0,1) == 'a')
{
if (!isset($v))
{
$sectionA_error = 1;
}
else
{
$sectionA_error = 0;
}
}
}
You could also try array_key_exists() instead of isset() ... both should
do the job.
Michael
> here is what i try to accpmplish:
> $key "name's" in an array are: a1, a2, a3, .... .
> $value dependes weather it has been checked, selected or entered.
>
> while (list($k, $v) = each($data))
> {
> for ($i=0; $i<count($k); $i++) {
> if (substr ($k[$i], 0, 1) == 'a') {
> if ($k == !$v) { // <-- ????
> $sectionA_error = 1;
> } else {
> $sectionA_error = 0;
> }
> }
> }
> }
> if ($sectionA_error) {
> echo "Nothing entered.\n<br>";
> } else {
> echo "at least one entry.\n<br>";
> }
>
> what i'm trying to get is:
> if there is a least one or doesn't matter how many values error = 0,
> if there is no value than error =1.
>
> cheers,
>
> Peter
>
>
>
--
--------------------------------
n i n t i . c o m
php-python-perl-mysql-postgresql
--------------------------------
Michael Hall ninti@ninti.com
--------------------------------