|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I searched around as much as I could for this, let me know if anyone
has some advice. I would like to actually output the name of the variable instead of the value. <snip> $requiredInt=array($amnt,$bNum,$rNum,$oNum,$numPay ments); $i=0; foreach ($requiredInt as $key => $val) { if (!filter_var($val, FILTER_VALIDATE_INT)) { echo('Item: '.!Output the variable name here!.' is required and must be a numeric integer, please go back and make this correction before submitting.<br />'); } $i++; } unset($requiredInt); </snip> Any advice is appreciated. Thank you. garrett |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Sep 18, 3:50 pm, kj <kils...@gmail.com> wrote:
> I searched around as much as I could for this, let me know if anyone > has some advice. I would like to actually output the name of the > variable instead of the value. > > <snip> > $requiredInt=array($amnt,$bNum,$rNum,$oNum,$numPay ments); > $i=0; > > foreach ($requiredInt as $key => $val) { > if (!filter_var($val, FILTER_VALIDATE_INT)) { echo('Item: '.!Output > the variable name here!.' is required and must be a numeric integer, > please go back and make this correction before submitting.<br />'); } > $i++;} > > unset($requiredInt); > </snip> > > Any advice is appreciated. Thank you. > garrett I'm not certain what you're asking, but I think you want to take $foo='bar' and get 'foo' out of it, which I'm almost certain can't be done. The easiest way to get around your problem is to set the key of each item equal to the name: $requiredInt=array('amnt'=>$amnt,'bNum'=>$bNum,'rN um'=>$rNum,'oNum'=> $oNum,'numPayments'=>$numPayments); Alternatively, if you want to avoid the repetition, you can just set the array to the string names: $requiredInt=array('amnt','bNum','rNum','oNum','nu mPayments'); Then in the foreach you can use $val to get the name of the variable and $$val to get its value. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Sep 19, 12:35 am, sysop...@gmail.com wrote:
> On Sep 18, 3:50 pm, kj <kils...@gmail.com> wrote: > > > > > I searched around as much as I could for this, let me know if anyone > > has some advice. I would like to actually output the name of the > > variable instead of the value. > > > <snip> > > $requiredInt=array($amnt,$bNum,$rNum,$oNum,$numPay ments); > > $i=0; > > > foreach ($requiredInt as $key => $val) { > > if (!filter_var($val, FILTER_VALIDATE_INT)) { echo('Item: '.!Output > > the variable name here!.' is required and must be a numeric integer, > > please go back and make this correction before submitting.<br />'); } > > $i++;} > > > unset($requiredInt); > > </snip> > > > Any advice is appreciated. Thank you. > > garrett > > I'm not certain what you're asking, but I think you want to take > $foo='bar' and get 'foo' out of it, which I'm almost certain can't be > done. The easiest way to get around your problem is to set the key of > each item equal to the name: > $requiredInt=array('amnt'=>$amnt,'bNum'=>$bNum,'rN um'=>$rNum,'oNum'=> > $oNum,'numPayments'=>$numPayments); > > Alternatively, if you want to avoid the repetition, you can just set > the array to the string names: > $requiredInt=array('amnt','bNum','rNum','oNum','nu mPayments'); > > Then in the foreach you can use $val to get the name of the variable > and $$val to get its value. Your assumption about what I tried to do was right. I tried your second solution, to avoid the repetition. It works perfectly and solved my issue. Thank you very much! |
|
![]() |
| Outils de la discussion | |
|
|