Reply to Re: [PHP] Dynamic Array Index using Variable

Your name:

Reply:


Posted by Al on 01/09/06 23:26

Jim Moseby wrote:
>>I want to do something like this to check if a variety of submitted
>>form fields (crn, instructor, etc) have any value in them:
>>
>>$reqfields = array('crn', 'instructor');
>>$errorflag = 0;
>>
>>foreach ($reqfields as $field) {
>> if ($_REQUEST[$field] == '') {
>> $errorflag = 1;
>> }
>>}
>>
>>But I can't quite get the syntax right... help??
>
>
> Something like this maybe?
>
> <? //untested
> foreach($array as $key=>$value){
> if(!isset($array[$key])){
> $errorflag = 1;
> }
> }
> ?>
>
>
> JM

That doesn't work. Only the last value is assigned;

if all you want to know is whether any one is empty, then

$err_msg= '';

foreach($array as $key=>$value){
if(empty($value)){
$err_msg= "$key is empty";
break;
}

echo $err_msg;

Or
$err_msg= '';

foreach($array as $key=>$value){
if(empty($value)){
$err_msg .= "$key is empty<br>";
}

echo $err_msg;

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация