0

Hi everyone,

I made a chunk of code where I wanted to perform a "for" loop within a concatenated string.
This is what I came up with:

$message = "The Top 5 Employees of the month are:" .
	for ($ctr = 0; $ctr < 5; $ctr++)
	{
		$num = $ctr + 1;
		$num . ". " . $helperNameArray[$ctr] . " helped " .
                       $helperCountArray[$ctr] . " customers." .
	}
	" ";

I haven't tested it yet and just wanted to confirm before testing if this is possible and if my code needs to be modified in any way.

Thanks.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by R0bb0b
0

Hi everyone,

I made a chunk of code where I wanted to perform a "for" loop within a concatenated string.
This is what I came up with:

$message = "The Top 5 Employees of the month are:" .
	for ($ctr = 0; $ctr < 5; $ctr++)
	{
		$num = $ctr + 1;
		$num . ". " . $helperNameArray[$ctr] . " helped " .
                       $helperCountArray[$ctr] . " customers." .
	}
	" ";

I haven't tested it yet and just wanted to confirm before testing if this is possible and if my code needs to be modified in any way.

Thanks.

You have several syntax and a couple logical errors.
From the way it looks, I thing this would be the best way to do it.

<?php
$message = "The Top 5 Employees of the month are:";
$helperNameCountArray = array_combine($helperNameArray, $helperCountArray);
arsort($helperNameCountArray, SORT_NUMERIC);
$counter = 0;
while (list($key, $value) = each($helperNameCountArray) && $counter < 5)
{
	$message .= "<br />" . $key . " helped " . $value . " customers";
	$counter++;
}
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.