Putting an array within an array?
am 24.08.2007 16:05:38 von Phil Latio
Still having fun trying to build the perfect form and validation classes and
wondered if anyone can help on the following.
In the following function, how can I make $validationparameters an array so
it can accept multiple values that I can iterate through? Don't need the
iteration part (yet).
function setField($type, $name, $value, $style, $label,
$validationparameter)
{
$this->number_of_fields++;
$this->fields[] = array('type'=>$type, 'name'=>$name, 'value'=>$value,
'style'=>$style, 'label'=>$label,
'validationparameters'=>$validationparameters);
}
This is part written function that I will use to pass the multiple values to
the array.
function setValidationParameters($number, $parameter)
{
$this->fields[$number][validationparameter] = $parameter;
}
I am beginning to confuse myself and wondering if anyone can add some sanity
to what I am doing.
Cheers
Phil
Re: Putting an array within an array?
am 24.08.2007 23:24:48 von Steve
"Phil Latio" wrote in message
news:RABzi.311528$tb2.204848@fe02.news.easynews.com...
| Still having fun trying to build the perfect form and validation classes
and
| wondered if anyone can help on the following.
such an animal does not exist. ;^)
| This is part written function that I will use to pass the multiple values
to
| the array.
|
| function setValidationParameters($number, $parameter)
| {
| $this->fields[$number][validationparameter] = $parameter;
| }
|
| I am beginning to confuse myself and wondering if anyone can add some
sanity
| to what I am doing.
unless you are telling php that 'validationparater' should be interpreted as
a string value:
$this->fields[$number][validationparameter] = $parameter;
should be:
$this->fields[$number][$validationparameter] = $parameter;
however, where would it come from in that function. in either case, with the
code as-is as posted here, the value of the field with key $number will have
a blank array element and its value will be the value of the $parameter the
last time you called the function...which is probably not what you were
going for.
PLUS, please keep your casing consistent with best practices...either camel
case, pascal case, or underscore your variables:
$validationParameter;
$ValidationParameter;
$validation_parameter;
respectively.