1

Here is my code

for ($i=0; $i<$Percentile["Parameter_length"]; $i++)
{
  echo "Eqt_Param".$i."=".$Percentile["Eqt_Param".$i]; 
}

The above code will display

Eqt_Param0=2.00
Eqt_Param1=3.00
Eqt_Param2=1.00
Eqt_Param3=5.00

If I put echo() outside the for loop, I need the same result. Please help me to fix this...

2 Answers 2

5

How about this? Simply concatenating the result of the foreach into a variable which can be echoed.

$output = "";
for ($i = 0; $i < $Percentile["Parameter_length"]; $i++)
{
    $output .= "Eqt_Param" . $i . "=" . $Percentile["Eqt_Param" . $i];
}

echo $output;
Sign up to request clarification or add additional context in comments.

Comments

0

You need to store your values in a viarable that exists outside of the scope of the for like:

$accumulatedString = '';
for ($i=0; $i<$Percentile["Parameter_length"]; $i++) { 
  echo "Eqt_Param".$i."=".$Percentile["Eqt_Param".$i]; 
  $accumulatedString .= "Eqt_Param".$i."=".$Percentile["Eqt_Param".$i];
}
echo $accumulatedString;

Thats if you want it all as one string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.