Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $prev1 = array(
- "ema99" => "0.0010309",
- "ema200" => "0.00010166",
- "price" => "0.00010670",
- "ema9" => "0.00010688",
- "ema20" => "0.00010616",
- "ema26" => "0.00010576",
- "ema50" => "0.00010448",
- );
- print_r(getColorRanges($prev1));
- function getColorRanges($prev1){
- $prev = array();
- $i = 0; // iterator to assign associative array
- $ref; // used to as index of price
- $temp; // to assign prev value to compare indexes if difference is -1 so it is in the order
- $t = true; // previously i gave it true as a considering sequence is in the order if once it is broken there is no chance of it is coming true and i false it
- $true = ['0' => 0 , '9' => 1, '20' => 2, '26' => 3, '50' => 4, '99' => 5, '200' => 6];
- foreach ($prev1 as $key => $value) {
- if($key == "price"){
- $prev[0] = $i;
- }
- else {
- $prev[substr($key,3,strlen($key)-3)] = $i;
- }
- $i++;
- }
- $ref = $prev[0];
- $i = 0;
- foreach ($prev as $key => $value) {
- if($prev[$key] < $ref){
- $prev1['ema'.$key] = 'red';
- }
- else if($prev[$key] == $ref){
- if ((($prev[0] > $prev[99] || $prev[0] > $prev[200]) && $ref <= 2) || $ref == 0) {
- $prev1['price'] = 'blue';
- }
- else if($ref == 6){
- $prev1['price'] = 'red';
- }
- else{
- $prev1['price'] = 'green';
- }
- }
- else {
- if(($true[$temp] - $true[$key] == -1) && $t){
- $prev1['ema'.$key] = 'blue';
- }else{
- $t = false;
- $prev1['ema'.$key] = 'green';
- }
- }
- $temp = $key;
- }
- return $prev1;
- }
Add Comment
Please, Sign In to add comment