cromestant Posted September 24, 2007 Share Posted September 24, 2007 Helo, first post here, although i m a usual reader. I have a small pickle with a script i m writting.. i need to intersect timestamps.. Let me explain : i have objects in my catalog. These objects change in percentaje in time intervals. So basically you could have for any given object from time 1 to time 10 --> 30%, from time 11 to time 24 ---> 40 %, from time 25 to time 50--> 10% This is modeled in my array in the folowing way $arr [1,10,11,24,25,50]. and i have another array with percentajes ( might change it to 2 dimensional single arrya soonish...) Now the problem is that i want to be able to create new intervals, so say for example in that example i want to insert from time 51 to70 another percentaje ( finall array beeing $arr [1,10,11,24,25,50,51,70]) or in the middle of an existing interval : 3->8 ($arr [1,2,3,8,9,10,11,24,25,50]) or in between 2 intervals 8 ->15 ($arr [1,7,8,15,16,24,25,50]) I don t know if i m making myself clear . hope i am, thanks for reading Charles Quote Link to comment https://forums.phpfreaks.com/topic/70485-merging-arrays/ Share on other sites More sharing options...
Psycho Posted September 24, 2007 Share Posted September 24, 2007 I think I understand. I also think you are over-complicating this. You don't need an array to hold the percentage, you should just create a function to detemine the percentages and call it when you need that data. Also, your array for determining the intervals does not need beginning and ending points. Either enter the beginning points or the ending points, not both. If you enter only the beginning points, then it is assumed that the end point is the number directly preceeding the next point. This is a quickly written example, I'm sure there are errors, but the logic should be valid //Only the start points $intervals = array (1,11,25,50); function returnPercentage($dataAry, $intervalsAry) { global $intervalStart, $intervalEnd; //this function will process the data array //and create an array of percentages to be returned $percentagesAry = array(); $totalCount = $count($dataAry); $intervals = count($intervalsAry); for ($i=0; $i<count($intervals); $i++) { $intervalStart = $intervalsAry[$i]; if ($i<($intervals-1)) { $intervalEnd = $intervalsAry[$i+1]; } else { $intervalEnd = false; } $intAry = array_filter($intervalStart, "getIntArray"); $intCount = count($intAry); $percentagesAry[] = $intCount / $totalCount; } return $percentagesAry; } function getIntArray ($var) { global $intervalStart, $intervalEnd; return ($var['intColName']>=$intervalStart && $var['intColName']>=$intervalEnd); } Quote Link to comment https://forums.phpfreaks.com/topic/70485-merging-arrays/#findComment-354139 Share on other sites More sharing options...
cromestant Posted September 24, 2007 Author Share Posted September 24, 2007 Thanks for reply.. will try that out although still think there is areason for why i included start and end dates... Quote Link to comment https://forums.phpfreaks.com/topic/70485-merging-arrays/#findComment-354382 Share on other sites More sharing options...
Psycho Posted September 24, 2007 Share Posted September 24, 2007 ... although still think there is areason for why i included start and end dates... Don't see why since you should be able to determine them programatically. Quote Link to comment https://forums.phpfreaks.com/topic/70485-merging-arrays/#findComment-354439 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.