PHP - Number of units between two numbers -


I am trying to find the number of units between 2 numbers, which is between 0 and one border between zero and that Exceed the limit. Here's my job, it works fine till I have to work with some big numbers which takes a lot of time to process. I am trying to find a way to execute this code without loop.

  getBetween public function ($ num1, $ num2) {$ limit = 500000; $ Array = array (0,0,0); If ($ num1> = $ num2) {$ lower = $ num2; $ High = $ num1; } And {$ cum = $ num1; $ High = $ num2; } ($ I = $ lower; $ i & lt; $ high; $ i ++) {if ($ i & lt; 0) {$ array [0] ++; } Otherwise ($ i & gt; = 0 & amp; $ i & lt; $ limit) {$ Sir [1] ++; } And {$ array [2] ++; }} Returned the $ array; }  

I have started dividing my loop into the elife statement, but it is actually messing up and I'll eventually be able to set more than one boundary which Will be impossible in

  If ($ lower <0 & amp; amp; amp; height> lt; 0) {} elseif ($ lower <0 & amp; amp; amp;; high & gt; = 0 & amp; amp;; high & lt; $ limit) {} Otherwise ($ lower> 0 & amp; high> gt; = $ range) {} Otherwise ($ min> Amp; $ lower <$ border & amp;; & amp;; amp; $ high & lt; 0) {} Otherwise ($ lower> = 0 & amp; amp; amp; $ & amp; & Amp; $ high> gt; = 0 & amp; amp; amp; amp; amp; high $ & lt; $ range) {} Otherwise ($ less> = 0 & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; $ Range & amp; $ high> gt; = $ range) {} Otherwise ($ lower> = $ border & amp; $ upper & lt;) () otherwise ($ lower> = $ range & amp; ; $ High> = 0 & amp; high> & lt; $ range) {} Otherwise ($ lower & gt; = $ Border & amp; $ high> gt; = $ border] {}  

I'm trying to find a clear way to do this. Any ideas?

Edit

Here's an example of the array I'm trying to get if my limit was 500, $ num1 = -100 and $ num2 = 700 I will get the array

  $ array [0] = $ 100 array array [1] = $ 500 = array [2] = I did not test it (a PHP script did not run, but I did not see any examples. With "manually").  

You still have the edge, but only one frequency per one per limit (instead of one per unit).

  // Example datas $ limits = array (0, 500, 800); $ Reduced = -100; $ High = 1000; $ SplittedResults = array (); // Total units of units total $ units = abus ($ high - $ lower); $ Total count = 0; Foreign Currency (as the $ Boundary $ limit) {If ($ lower> gt; $ limit) {// nothing below the limit $ nbUnderLimit = 0; } Otherwise ($ high> $ border) {// Both prices are $ nbUnderLimit = $ totalUnits; } Else {$ $ $ $ $ $ below the range and $$$ nbUnderLimit = abs ($ range - $ less); } // We know here that at present, the total units are in the total range. // We want to know how much is between the previous border and current limit. Let us assume that the boundaries are ascending, we have already counted units $ NbBetweenLimits = $ nbUnderLimit - $ Total Compensation; $ SplittedResults [] = $ nbBetweenLimits; $ Total charge + = $ nbBetweenLimits; } / Finally, the number of units over the last limit (left) $ splittedResults [] = $ totalUnits - $ total count;  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -