vendredi 17 mars 2023

how to build a expression with a lot of variables having the same name pattern?

i have 50 variables in my system script. All have the same kind of naming like :

$case_un
$case_deux
$case_trois
...
$case_fourthy

I need to build a expression with all of them without writing the code of 50 variables names !

As all my variables'name begin by the pattern 'case_', is there a syntaxe to make the SUM of them or another expression ?

i need to perform such thing :

   $test_of_cases = $case_un && $case_deux && $case_trois && ...........$case_fourthy ;

and also that thing :

  $total_of_sums = $sum_un + $sum_deux + ............$sum_fifthy ;

so, is there a way to code that in PHP ? In formal language, i just need to SUM all the variables which name begins by 'case_' .

My 50 variables are not storable in a array because there are from differents sources & expression result.

I'm not sure, but i thing there is a kind of expression to perform that in other language :

    LET a=SUM (`*case_*`)
    LET b=XOR (`*case_*`)
    LET c=AND (`*case_*`)

i learnt that in my old studies 30years ago.....

i hope PHP can do the same, else not, i have to write 50 lignes of code !

Best regards

Aucun commentaire:

Enregistrer un commentaire