I want to echo, before the loop, a variable that is inside the loop.
How can it be done?
Getting a variable from a loop
Moderator: General Moderators
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Getting a variable from a loop
You'll have to be more specific and maybe show some code/pseudo code.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Getting a variable from a loop
for example to get the $i and echo it before the foreach, is it possible?
foreach($rows as $row) {
$i++;
}
foreach($rows as $row) {
$i++;
}
Re: Getting a variable from a loop
What would be the value of $i before going through the loop?
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Getting a variable from a loop
So:
Would print out '0', but I'm guessing that's not what you had in mind. Maybe you should share with us your specific issue
Code: Select all
$i = 0;
echo $i;
foreach($rows as $row) {
$i++;
}