Page 1 of 1

Use variable in $data

Posted: 2020-07-16 09:33
by peteraj
Hi,

Is it possible to "index into" the $data['fieldname'] array? I have tried: $data['fieldname[X]'] but it didn't work..

a little example of what I want:

fieldnames = array("fieldname1","fieldname2","fieldname3");

for ($x = 0; $x <= 10; $x++) {
$data( [fieldname[x] ) = something;
}

I have fields both before and after the fields I want to alter, so I would preffer not to loop through all the fields in the table...

I hope you understand my explanation, any help is appriciated, thank you :-)

Kind regards
Peter

Re: Use variable in $data

Posted: 2020-07-16 12:59
by jsetzer

Code: Select all

$fieldnames = ["fieldname1", "fieldname2"];
foreach ($fieldnames as $fieldname) {
  // your code
  // for example
  // $data[$fieldname] = strtoupper($data[$fieldname]);
}

Re: Use variable in $data

Posted: 2020-07-16 13:54
by peteraj
Cool, as simple as that! Thank you :-)