You are here: Re: array_walk - userdata as array by ref « PHP Programming Language « IT news, forums, messages
Re: array_walk - userdata as array by ref

Posted by Steve on 04/20/07 04:39

| Both of the code you posted did not work on my box (php5.2) unmodified.
|
| My initial thought will be using foreach on the array $numbers, but you
| might have your own reason not to use it.

i usually do. however, i'm prototyping something. here's what gives me the
results...in case my free-handed post is why it doesn't work on your box.
thanks for looking at it. sorry for the text-wrapping here...if you just
backspace the wrap, it should be very easy to read/follow.

<?
$inputs['Personnel'] = array(
'bodyTech' => 0 ,
'bodyTechAppr' => 0 ,
'paintTech' => 0 ,
'paintTechAppr' => 0 ,
'paintPreps' => 0 ,
'mechanicTechs' => 0 ,
'estimators' => 0 ,
'otherEmployees' => 0
);
$inputs['Facility'] = array(
'bodyShopLocation' => '' ,
'franchises' => '' ,
'totalSqFeet' => 0 ,
'productionSqFeet' => 0 ,
'totalWorkStations' => 0 ,
'totalPaintBooths' => 0 ,
'totalDetailStalls' => 0
);
function retrieveInput(&$value, $key, $source)
{
$default = 0;
if ($key == 'bodyShopLocation'){ $default = ''; }
if ($key == 'franchises'){ $default = ''; }
$value = isset($source[$key]) ? $source[$key] : $default;
}
function validateInput(&$value, $key, &$errors)
{
$inputName = '';
$maxValue = 999;
switch ($key)
{
case 'bodyShopLocation' : if (in_array($value, array('', 'ON SITE',
'OFF SITE'))){ return; }
$errors[$key] = 'BODY SHOP LOCATION must be
either on-site or off-site.';
return;
break;
case 'franchises' : if (in_array($value, array('', 'SINGLE',
'MULTIPLE'))){ return; }
$errors[$key] = 'FRANCHISE TYPE must be
either single or multiple.';
return;
break;
case 'bodyTech' : $inputName = 'BODY TECHNICIANS';
break;
case 'bodyTechAppr' : $inputName = 'BODY TECHNICIAN APPRENTICES';
break;
case 'paintTech' : $inputName = 'PAINT TECHNICIANS';
break;
case 'paintTechAppr' : $inputName = 'PAINT TECHNICIAN APPRENTICES';
break;
case 'paintPreps' : $inputName = 'PAINT PREPS';
break;
case 'mechanicTechs' : $inputName = 'MECHANICAL TECHNICIANS';
break;
case 'estimators' : $inputName = 'ESTIMATORS';
break;
case 'otherEmployees' : $inputName = 'OTHER EMPLOYEES';
break;
case 'totalSqFeet' : $inputName = 'TOTAL SQUARE FEET';
$maxValue = 9999999; break;
case 'productionSqFeet' : $inputName = 'PRODUCTION AREA SQUARE FEET';
$maxValue = 9999999; break;
case 'totalWorkStations' : $inputName = 'TOTAL WORK STATIONS';
break;
case 'totalPaintBooths' : $inputName = 'TOTAL PAINT BOOTHS';
break;
case 'totalDetailStalls' : $inputName = 'TOTAL DETAIL STALLS';
break;
default : return; break;
}
if ($value <= $maxValue) return;
$errors[1][$key] = $inputName . ' must be a whole number between 0 and ' .
$maxValue . '.';
}
array_walk($inputs['Personnel'], 'retrieveInput', $_REQUEST);
array_walk($inputs['Facility'], 'retrieveInput', $_REQUEST);
$error = array();
$errors = array('', &$error);
array_walk($inputs['Personnel'], 'validateInput', $errors);
array_walk($inputs['Facility'], 'validateInput', $errors);
$errors = count($errors) > 1 ? $errors[1] : array();
echo '<pre>' . print_r($inputs, true) . '</pre>';
echo '<pre>' . print_r($errors, true) . '</pre>';
?>

 

Navigation:

[Reply to this 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

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