Jump to content

Recommended Posts

Right, I have a loop which is meant to create an array for every price increment on betfair. There are three arrays, one to define the start of a range ($range_s), one to define the end ($range_f), and the other to define the increments within that range ($range_i). e.g 1.01-2 has increments of 0.01, 2.02-3 has increments of 0.02 etc. The index in each array is common to that range so $range_s[0], $range_f[0] and $range_i[0] all define the first range.

 

Simply, I have a loop that calculates the number of increments within a range, assigns the first value to the array, and then adds the next increment to the array by just adding the increment amount to the previous index value.

 

So, I have created the script, fired it up and all appears correct. But wait, whats this? PHP has decided to miss out the value 10. Just 10. Nothing else. I have tried to figure out why, but I just dont know why it is doing it.

 

So, with a drum roll, here is the function that has driven me to near suicide.

 

<?php
$j = 0; //used to reference the previous pip value
foreach($range_i as $key => $increment)
{
	$pips[] = $range_s[$key]; //add the start of the range to the pip array
	$total_range_pips = ($range_f[$key] - $range_s[$key]) / $increment; //how many increments are there within the range
	for($i = 1; $i <= $total_range_pips; $i++)
	{
		$pips[] = $pips[$j] + $increment; //add an increment onto the last entered value
		$j++;
	}
	$j++;
}

 

I can post the arrays that define the ranges on request. Any help on this would be much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/155548-insubordinate-php/
Share on other sites

you probably don't need to keep tabs you could just use current

 

for example:

 

<?php
foreach($range_i as $key => $increment)
{
      $pips[] = $range_s[$key]; //add the start of the range to the pip array
      $total_range_pips = ($range_f[$key] - $range_s[$key]) / $increment; //how many increments are there within the range
      for($i = 1; $i <= $total_range_pips; $i++)
      {
         $pips[] = current($pips) + $increment; //add an increment onto the last entered value
      }
}
?>

 

also other thoughts, if finish is lower than start, you could encounter other errors..

Link to comment
https://forums.phpfreaks.com/topic/155548-insubordinate-php/#findComment-818740
Share on other sites

If I understand correctly range does what you need.

 

Hmm, that is a useful function. I have started using that instead and it works fine. Cuts down the code to a few lines too. I still don't know why it wasn't working; I was actually having to add the value 10 to the end of the array and then sort it.

 

Thank you for the help

Link to comment
https://forums.phpfreaks.com/topic/155548-insubordinate-php/#findComment-819125
Share on other sites

Hmm, that is a useful function. I have started using that instead and it works fine. Cuts down the code to a few lines too. I still don't know why it wasn't working; I was actually having to add the value 10 to the end of the array and then sort it.

 

Thank you for the help

 

Can you post an updated version of the code you are using now?

Link to comment
https://forums.phpfreaks.com/topic/155548-insubordinate-php/#findComment-819127
Share on other sites

Here you go. By changing the values within the $range arrays, it is possible to generate an array of increments for other exchanges too such as Betdaq, WBX etc. Working on a Betfair script yourself?

 

<?php
$range_s[] = 1.01; //range start arrays
...
$range_s[] = 110;

$range_f[] = 2; //range finish arrays
...
$range_f[] = 1000;

$range_i[] = 0.01; //range increment arrays
...
$range_i[] = 10;


$pips = array();
foreach($range_i as $key => $range_increment)
{
$pips_t = range($range_s[$key],$range_f[$key],$range_i[$key]);
$pips = array_merge($pips,$pips_t);
}

Link to comment
https://forums.phpfreaks.com/topic/155548-insubordinate-php/#findComment-819223
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.