0

here is my code

for ($i=0; $i<$Percentile["Parameter_length"]; $i++)
{
  $parameters.="Eqt_Param".$i."=".$Percentile["Eqt_Param".$i]; 
  $Per_Wtg.="Per_Wtg".$i."=".$Percentile["Eqt_Param".$i]/100;
}

if i display(echo $Per_Wtg;) $per_wtg outside for loop i get

'Per_Wtg0=0.03 Per_Wtg1=0 Per_Wtg2=0 Per_Wtg3=0'

well i have one more code

for ($i=0; $i<$Percentile["min_length"]; $i++)
{
    $min.="Eqt_Min".$i."=".$Percentile["Eqt_Min".$i];
}

if i display(echo $min;) $min outside for loop i get

'Eqt_Min0=1.00Eqt_Min1=1.00Eqt_Min2=1.00Eqt_Min3=1.00'

but now i need display one more array variable

$Eqt_Sr0=($Per_Wtg0-$Eqt_Min0) ,
$Eqt_Sr1=($Per_Wtg1-$Eqt_Min1) , 
$Eqt_Sr2=($Per_Wtg2-$Eqt_Min2) , 
$Eqt_Sr3=($Per_Wtg3-$Eqt_Min3) 

to make this i may have to take one more array $Eqt_Sr

but how to display this outside for loop anyways to fix this?

2
  • please take some time to format your code correctly, thanks! Commented Nov 28, 2012 at 20:53
  • k dear..sorry i was bit hurry ,,i will make sure it does not happen again.. Commented Nov 28, 2012 at 20:54

2 Answers 2

1

Just do this:

$Eqt_Sr = array();

for ($i=0; $i<$Percentile["Parameter_length"]; $i++)
{
  $parameters.="Eqt_Param".$i."=".$Percentile["Eqt_Param".$i]; 
  $Per_Wtg.="Per_Wtg".$i."=".$Percentile["Eqt_Param".$i]/100;

  /*Look the array $Eqt_Sr*/
  $Eqt_Sr[$i] = $Percentile["Eqt_Param".$i]/100;
}

Then:

for ($i=0; $i<$Percentile["min_length"]; $i++)
{
    $min.="Eqt_Min".$i."=".$Percentile["Eqt_Min".$i];

    // Add here
    $Eqt_Sr[$i] =  $Eqt_Sr[$i] - $Percentile["Eqt_Min".$i];
}

To display the array:

for($i=0; $i<count($Eqt_Sr); $i++){
   $output .= "Eqt_Sr".$i."=(".$Eqt_Sr[$i]."),";
}
Sign up to request clarification or add additional context in comments.

5 Comments

Now you can use the $Eqt_Sr to display "$Eqt_Sr0=($Per_Wtg0-$Eqt_Min0)" using for
if i display $Eqt_Sr outside for loop it is displayed as Array :( how to fix this?
hmm k k .. can you also tell me one thing ... i want create variable $Eqt_Min=Eqt_Min0+$Eqt_Min1+$Eqt_Min2+$Eqt_Min3 how to do that??
You can use 'for' again, but $output += $Eqt_min[$i]
Oh wait... if you used $output before, try to use $output2 ou another variable. The variable's names its just a suggestion.
0

Your code is an absolute mess, and its impossible to tell what it is you are actually looking for, but I'll take a guess at it.

Not sure why you are using 'Parameter_length' and 'min_length' as you appear to expect them to always be the same value - But what happens if they are different? My code below deals with the case of min_length >= Parameter_length, but not min_length < Parmeter_length

script

<?php

// Data assumed from inspection of original post
$Percentile = array
(
        'Eqt_Param0' => 3.00,
        'Eqt_Param1' => 0.00,
        'Eqt_Param2' => 0.00,

        'Parameter_length' => 3,

        'Eqt_Min0' => 1.00,
        'Eqt_Min1' => 1.00,
        'Eqt_Min2' => 1.00,

        'min_length' => 3,
);

$Parameters = array();
$Per_Wtg    = array();
$Eqt_Min    = array();
$Eqt_Sr     = array();

for ($i = 0; $i < $Percentile['Parameter_length']; $i++)
{
    $param = $Percentile["Eqt_Param{$i}"];
    $wtg   = $param / 100;

    $Parameters[$i] = $param;
    $Per_Wtg[$i]    = $wtg;
}

// TODO What if 'min_length' != 'Parameter_length' ??
for ($i = 0; $i < $Percentile['min_length']; $i++)
{
    $param = $Percentile["Eqt_Param{$i}"];
    $min   = $Percentile["Eqt_Min{$i}"];

    $Eqt_Min[$i] = $min;
    $Eqt_Sr[$i]  = ( array_key_exists($i, $Parameters) ? $Parameters[$i] : 0 ) - $min;
}

print " Parameters => " . join(', ', $Parameters) . "\n";
print " Per_Wtg    => " . join(', ', $Per_Wtg   ) . "\n";
print " Eqt_Min    => " . join(', ', $Eqt_Min   ) . "\n";
print " Eqt_Sr     => " . join(', ', $Eqt_Sr    ) . "\n";

output

 Parameters => 3, 0, 0
 Per_Wtg    => 0.03, 0, 0
 Eqt_Min    => 1, 1, 1
 Eqt_Sr     => 2, -1, -1

1 Comment

thanks alot for trying dear... iam passing arrays through javascripts bcos its ajax page ... thats the reason it looks messy...

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.