dynamic field

Hello,
I would like to increment a field name in a foreach
ex:
$ x = 0;
foreach ({sel_ref} = $ ref)
{
$ X ++;
{name $ x} = funct ($ x, a, b);
}
in order to have {name1} = 10800;
{name2} = 108001;
{…} = …;
thanks for your advices, …

If this code was copied from your application then be aware that variable names are case sensitive in PHP. |So $X++ should be $x++
I’m not sure however if you can dynamically form names and assign values to them. Might be with an eval .

I think you can to create your 14 fields manually and they can be used for your need.

I think you can do it this way:.

switch ($i) {
case 1:
{name1} = 108001;
break;
case 2:
{name2} = 108005;
break;
case 3:
{name3} = 108007;
break;
case …
}

i learn that now :rolleyes:, thanks

@alvagar How does that apply to the scriptcase field variables? Like {myfield} ? I would like to dynamically access the field names using variables.
In my case I have a form with over 100 fields on it, and I need to check if data exists in those fields. Rather than code 100 if {myfield} statements I want to read in the names of all the fields directly from that database… (I have that part working) and loop through the array checking each field kind of like above.

Any idea how I can accomplish this?

Example:
$fieldvar = ‘myfield’;

If( {$fieldvar} == ‘’){Echo $fieldvar." is emtpy";}

But this fails as {$fieldvar} isn’t the way to do this.

Thanks!

the real difficulty is to be able to convert the concatenation of the chains into a variable already declared and recognized, the result is always identified as chain of text, it would be necessary to recover the id of the field and to concatenate this id with the increment, for the value of 0 to 100, just use range (0,100) as a loop value, I always manage to reproduce the concatenation, but never to read it as variable, my part statement is correct but the reading is only text: ex:
$ var [0] = {x1} (where x1 is the concatenated variable)

thank you, this solution will be part of my references, after a lot of testing, I was finally able to create this little routine that corresponds exactly to what I expect and may be able to help “yourguide”, thank you all for your advice ,
///
$ x = 1;
foreach (range (1.14) as $ x)
{
$ txt = ‘sp’;
$ txt. = $ x;

$ val_field = $ _POST [$ txt];
echo $ val_field. ‘</ br>’;
}
///

thank you, this solution will be part of my references, after a lot of testing, I was finally able to create this little routine that corresponds exactly to what I expect and may be able to help “yourguide”, thank you all for your advice ,
///
$ x = 1;
foreach (range (1, 14) as $ x)
{
$ txt = ‘sp’;
$ txt. = $ x;

$ val_field = $ _POST [$ txt];
echo $ val_field. ‘</ br>’;
}
///
Carefully read (range (1,14)

@nsch2308 , while it isn’t directly what I need it does provide me other options on the subject and will help me determine my solution.
Thank you for posting your solution!