Tristan Warren
Tristan Warren

Reputation: 435

How to use a variable used in 'for' loop PHP?

when using a for loop in PHP are the variables used inside available outside of the loop and if not is there a way of doing so?

foreach ($rows as $row){
    $name = $row ['surname'];
    $validpassword = ($validpassword + 1);
}

Will I be able to use $validpassword outside of the loop?

Upvotes: 1

Views: 59

Answers (1)

Devon Bessemer
Devon Bessemer

Reputation: 35337

Yes, the variable scope is not limited to the loop.

Upvotes: 3

Related Questions