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.

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++;
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.