Connecting Tech Pros Worldwide Forums | Help | Site Map

Putting an array within an array?

Phil Latio
Guest
 
Posts: n/a
#1: Aug 24 '07
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





Phil Latio
Guest
 
Posts: n/a
#2: Aug 24 '07

re: Putting an array within an array?


Ignore my post as I can't even type properly !!!

Cheers

Phil


Steve
Guest
 
Posts: n/a
#3: Aug 24 '07

re: Putting an array within an array?



"Phil Latio" <phil.latio@f-in-stupid.co.ukwrote in message
news:RABzi.311528$tb2.204848@fe02.news.easynews.co m...
| 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.


Closed Thread