Jump to content
Server Maintenance This Week. ×

PHP: How do I create a numbered sequence in a foreach loop?


This topic is 3130 days old. Please don't post here. Open a new topic instead.

Recommended Posts

In normal PHP, you would do something like this:

<?php
$arr 
= array("one""two""three");

$c = 1;
foreach ($arr as $value) {
    echo $c.
") ".$value."<br />\n";
    $c++;
}

?>

Does this help?

Link to comment
Share on other sites

If you need to set a "value" for each row returned (sort of like the @@ in FileMaker layout mode), based on the sorted results, of course:

I couldn't find any method that does this, but may be a differnt method.

 

Before loop, set $varCount to 0

$varCount = 0;

 

Then in each for-each loop (within table cell if needed) to output other found results:

 

$varCount = $varCount + 1;

echo $varCount;

 

There may be a return value for the Row Num or such in the XML results, I just don't know at the moment. If there is, than you can use that value. the xml value for the element resultset attribute 'count' of course would give you how many records/rows are returned.

 

  • Like 1
Link to comment
Share on other sites

This topic is 3130 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.