-3


Can I change the variable names used in foreach in PHP?

foreach ($sql2htmlLists as $kkkkk => $vvvvv){

instead of the default:

foreach ($sql2htmlLists as $key => $value){

Thank you

NicoESIEA
  • 499
  • 1
  • 6
  • 23
  • Why you can't ? – executable Mar 18 '19 at 13:12
  • 3
    Simple answer = YES. ___Obvious Question: Why didn't you just try it and see for yourself___ – RiggsFolly Mar 18 '19 at 13:14
  • 1
    The variable names you use for `as $key => $value` are completely up to you. You are actually creating 2 new variables in that command so call them anything you like ___that makes sense! so others can understand your code___ So `$kkkkk => $vvvvv` is probably not the best naming convention :) – RiggsFolly Mar 18 '19 at 13:16
  • You are right RiggsFolly - I posted before test before my architecture is too slow - I have to wait couple of minutes before see the result... Welcome in the XIV century ^^ hihi – NicoESIEA Mar 23 '19 at 07:56

1 Answers1

0

Yes, you can use whatever you want

foreach ($sql2htmlLists as $key => $value){

}

But i suggest you to use proper variables.And try to unset that variables at the end of loop to get out from conflicts.

Future Coder
  • 124
  • 2
  • 9