drunkenMonkey Posted December 2, 2012 Share Posted December 2, 2012 Hello, I'm new to this forum, so if I posting this question at the wrong board, please move it to the correct place . I'm having a math problem on wich I have been breaking my head for a few days. I want to write a PHP-script that can calculate the "smallest" match possible between 2 arrays. I just don't know how to get started. I'll give an example on what I'm looking for: $array1 = array(10, 25, 37, 68, 73, 82); $array2 = array(11, 26, 38, 69, 74, 83); So let's calculate the possibilities off $array1: 1 x 10 = 10 (numbers used: 1) 2 x 10 = 20 (numbers used: 2) 1 x 25 = 25 (numbers used: 1) 3 x 10 = 30 (numbers used: 3) 1 x 10 + 1 x 25 = 35 (numbers used: 2) 1 x 37 = 37 (numbers used: 1) 4 x 10 = 40 (numbers used: 4) 2 x 10 + 1 x 25 = 45 (numbers used: 3) 1 x 10 + 1 x 37 = 47 (numbers used: 2) 5 x 10 = 50 (numbers used: 5) 2 x 25 = 50 (numbers used: 2) 3 x 10 + 1 x 25 = 55 (numbers used: 4) 2 x 10 + 1 x 37 = 57 (numbers used: 3) 6 x 10 = 60 (numbers used: 6) 1 x 25 + 1 x 37 = 62 (numbers used: 2) 4 x 10 + 1 x 25 = 65 (numbers used: 5) 3 x 10 + 1 x 37 = 67 (numbers used: 4) 1 x 68 = 68 (numbers used: 1) 7 x 10 = 70 (numbers used: 7) ... Now calculate the possibilities off $array2: 1 x 11 = 11 (numbers used: 1) 2 x 11 = 22 (numbers used: 2) 1 x 26 = 26 (numbers used: 1) 3 x 11 = 33 (numbers used: 3) 1 x 11 + 1 x 26 = 37 (numbers used: 2) STOP As you can see we have a match on the number 37, wich is the smallest possible match between the 2 arrays. I want PHP to output the smallest possible match + for each row how you can get to that match. Some facts that might make the programming easier: both arrays will always have exact 6 numbers the values in the arrays will always be sorted from low to high the highest possible numbers that can be used is 150, so 150 x $array[5] is the highest possible value we can get Can anyone help met getting started at this problem . Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/ Share on other sites More sharing options...
requinix Posted December 3, 2012 Share Posted December 3, 2012 (edited) How does 10+73=83 fit into the problem? [edit] And are you prepared for the 140,515,219,945,627,518,837,736,801 possible combinations to examine before returning failure? Edited December 3, 2012 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1397258 Share on other sites More sharing options...
drunkenMonkey Posted December 3, 2012 Author Share Posted December 3, 2012 How does 10+73=83 fit into the problem? [edit] And are you prepared for the 140,515,219,945,627,518,837,736,801 possible combinations to examine before returning failure? Thanks for your reply 10+73=83 => This is indeed a possible answer, but I'm looking for the lowest possible match... wich in this case is 37. are you prepared for the 140,515,219,945,627,518,837,736,801 possible combinations to examine before returning failure? => Are there really so many possible combinations :-\. Well I guess PHP will not be able to calculate all possibilites before trowing a memory exception, but I don't care about that. In most cases a match will be found really fast, so I want the script to keep looking for a match until he finds the match or untill it trows an exception. I don't want PHP to do any useless calculations so for each possibility calculated for array1 we need to look if there's a possible match in array2... if not we calculate the next value, and so on... I guess the solution might be more complicated as I thought at first :'( Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1397278 Share on other sites More sharing options...
Psycho Posted December 3, 2012 Share Posted December 3, 2012 It looks like you are trying to compare the values of each number combination in the arrays multiplied by different values. So, there isn't 140,515,219,945,627,518,837,736,801 possible combinations - the possible combinations is infinite. And, knowing how many combinations would need to be tested before finding a match would require some math that makes my head hurt. The difficult part, from my perspective, would be in trying to develop the logic to know what the next highest combination would be since the numbers are dynamic. But, here is the logic I would use: 1. Create an index variable to count the number of iterations through the loop. Then use the variable to exit the loop at a set number of iterations when a match is not found. This will prevent you from getting stuck in an infinite loop or one that will cause a timeout issue. 2. Create a process to get the next highest combination from an array. This is the hard part. 3. In the loop, have the process continue as long as no match is found and the loop counter has not reached the maximum value. 4. Do a test between the current calculated value between array 1 and array 2. If they are equal, then set the value in a variable and exit the loop. If they are not equal then increment the value of the one that is less than the other. Repeat Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1397289 Share on other sites More sharing options...
requinix Posted December 3, 2012 Share Posted December 3, 2012 (edited) There's a kinda brute-force method on determining the next combination, which I agree with Psycho to be the hardest part, but I'm still thinking if there's a smarter alternative. are you prepared for the 140,515,219,945,627,518,837,736,801 possible combinations to examine before returning failure? => Are there really so many possible combinations . Well I guess PHP will not be able to calculate all possibilites before trowing a memory exception, but I don't care about that. About that number: I calculated that assuming you can devise an expression in one array to match an expression in the other array. Not that it's one expression totaling a single number. Like $array1 = array(2, ; $array2 = array(3, 7, 20); and 2+8=3+7 (4) is the best answer, as opposed to 2*2+8*2=20 (4 but higher). Otherwise it's just 151 ^ 6 = 11,853,911,588,401 combinations. (151 because 0 is a valid multiplier - the term isn't in the equation) Well I guess PHP will not be able to calculate all possibilites before trowing a memory exception, but I don't care about that. 1. It would be a fatal error, not a catchable exception. The script would die. 2. Written well there wouldn't be any memory problems - it would just take a really, really long time to stop. It looks like you are trying to compare the values of each number combination in the arrays multiplied by different values. So, there isn't 140,515,219,945,627,518,837,736,801 possible combinations - the possible combinations is infinite. There's a maximum of 150 on the multiplier. Edited December 3, 2012 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1397291 Share on other sites More sharing options...
drunkenMonkey Posted December 3, 2012 Author Share Posted December 3, 2012 So, there isn't 140,515,219,945,627,518,837,736,801 possible combinations - the possible combinations is infinite. Well, it's not infinite. As I stated in my first post the maximum multiplier is "150", so the largest possible match is 150 x $array1[5] 2. Create a process to get the next highest combination from an array. This is the hard part. Yes, it's this process/function that I need... but I can't seem to find how to calculate the next combination.... I don't like a brute force aproach... but if this is the only way this can be achieved, so be it . Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1397297 Share on other sites More sharing options...
drunkenMonkey Posted December 10, 2012 Author Share Posted December 10, 2012 Well, I've made a script. At this moment it's brute force and it calculates all possible matches between the arrays (up to 4 arrays). However at max it can calculates matches for up to 20 hits (wich takes 20 seconds / array). Any ideas on how I can make this script better and faster so it can calculates up to 50 hits or maybe 150 as stated in the first post? <?php $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; ini_set("memory_limit","4096M"); set_time_limit(90); $player[1] = isset($_POST["id1"]) ? floatval($_POST["id1"]) : 0; $player[2] = isset($_POST["id2"]) ? floatval($_POST["id2"]) : 0; $player[3] = isset($_POST["id3"]) ? floatval($_POST["id3"]) : 0; $player[4] = isset($_POST["id4"]) ? floatval($_POST["id4"]) : 0; $server = $_POST["server"]; $hits = floatval($_POST["hits"]); function getPlayerInfo(&$id, &$server){ $string = file_get_contents('http://'.$server.'.e-sim.org/apiCitizenById.html?id='.$id); $array = json_decode($string, true); $ranksArray = json_decode(file_get_contents('http://e-sim.org/apiRanks.html'),true); foreach ($ranksArray as $key => $val) { if ($val['name'] === $array['rank']) { $array['modifier'] = floatval($val['damageModifier']); } } return $array; } for ($i = 1; $i <=4; $i++){ if ($player[$i] > 0){ $player[$i] = getPlayerInfo($player[$i],$server); $player[$i]['wepdamage'] = array(floor(0.5*$player[$i]['strength']*$player[$i]['modifier']),floor(1.2*$player[$i]['strength']*$player[$i]['modifier']),floor(1.4*$player[$i]['strength']*$player[$i]['modifier']),floor(1.6*$player[$i]['strength']*$player[$i]['modifier']),floor(1.8*$player[$i]['strength']*$player[$i]['modifier']),floor(2*$player[$i]['strength']*$player[$i]['modifier'])); } else { unset($player[$i]); } } echo"<table><tr>"; foreach ($player as $key => $val){ echo"<td width='".(100/count($player))."%'>"; echo "<b>",$val['login'],"</b> | Strength: ",$val['strength']," | Rank: ",$val['rank'],"<br>"; echo "q0: ",$val['wepdamage'][0]," | q1: ",$val['wepdamage'][1]," | q2: ",$val['wepdamage'][2]," | q3: ",$val['wepdamage'][3]," | q4: ",$val['wepdamage'][4]," | q5: ",$val['wepdamage'][5]; echo "</td>"; flush(); } echo"</tr><tr>"; function calculatePos(&$player,&$hits){ $pos = array(); $arr = array(); $arr1 = array(); $arr2 = array(); $arr3 = array(); $arr4 = array(); $arr5 = array(); $count = 0; for ($j = 0; $j <=5; $j++){ for ($i = 1; $i <= $hits; $i++){ $arr[$j][$i] = $i * $player[$j]; $pos[$i." x q".$j] = $i * $player[$j]; $count++; } } for ($j = 0; $j <=4; $j++){ for ($i = 0; $i <= $hits; $i++){ if ($i > 0){ $q0 = $i." x q".$j." | "; } else { $q0 = ""; } for ($k = $j+1; $k <=5; $k++){ for ($l = 0; $l+$i <=$hits; $l++){ if ($l > 0){ $q1 = $l." x q".$k." | "; } else { $q1 = ""; } $pos[$q0."".$q1] = $arr[$j][$i] + $arr[$k][$l]; $count++; for ($m = $k+1; $m <=5; $m++){ for ($n = 0; $n+$l+$i <=$hits; $n++){ if ($n > 0){ $q2 = $n." x q".$m." | "; } else { $q2 = ""; } $pos[$q0."".$q1."".$q2] = $pos[$q0."".$q1] + $arr[$m][$n]; $count++; for ($o = $m+1; $o <=5; $o++){ for ($p = 0; $p+$n+$l+$i <=$hits; $p++){ if ($p > 0){ $q3 = $p." x q".$o." | "; } else { $q3 = ""; } $pos[$q0."".$q1."".$q2."".$q3] = $pos[$q0."".$q1."".$q2] + $arr[$o][$p]; $count++; for ($q = $o+1; $q <=5; $q++){ for ($r = 0; $r+$p+$n+$l+$i <=$hits; $r++){ if ($r > 0){ $q4 = $r." x q".$q." | "; } else { $q4 = ""; } $pos[$q0."".$q1."".$q2."".$q3."".$q4] = $pos[$q0."".$q1."".$q2."".$q3] + $arr[$q][$r]; $count++; for ($s = $q+1; $s <=5; $s++){ for ($t = 0; $t+$r+$p+$n+$l+$i <=$hits; $t++){ if ($t > 0){ $q5 = $t." x q".$s." | "; } else { $q5 = ""; } $pos[$q0."".$q1."".$q2."".$q3."".$q4."".$q5] = $pos[$q0."".$q1."".$q2."".$q3."".$q4] + $arr[$s][$t]; $count++; } } } } } } } } } } } } //echo $count."<br>" ; return $pos; } foreach ($player as $key => $val){ $pos[$key] = calculatePos($val['wepdamage'],$hits); } if (count($pos) > 0){ $result = $pos[1]; } if (count($pos) > 1){ $result = array_intersect($pos[1], $pos[2]); } if (count($pos) > 2){ $result = array_intersect($result, $pos[3]); } if (count($pos) > 3){ $result = array_intersect($result, $pos[4]); } foreach ($pos as $key => $val){ $resultArray[$key] = array_intersect($val,$result); asort($resultArray[$key]); echo"<td valign='top'><pre>"; print_r($resultArray[$key]); echo"</pre></td>"; } echo"</tr></table>"; $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = ($endtime - $starttime); echo "<br><br>This page was created in ",$totaltime," seconds"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1398496 Share on other sites More sharing options...
Christian F. Posted December 10, 2012 Share Posted December 10, 2012 I can't say anything for sure without some test data to profile it with, and I don't want to have to go chasing down the server name and/or player IDs... One thing I did notice right away, except the ridiculous amount of nested loops, is that you've concatenated with empty strings. That's completely unnecessary, same as writing 1 + 2 like this: 0 + 1 + 0 + 2 + 0. Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1398504 Share on other sites More sharing options...
drunkenMonkey Posted December 10, 2012 Author Share Posted December 10, 2012 Hey, Thx for your reply. I'm concatenating empty strings because I don't know if they are empty or not. But I guess that could have been done better... I'm happy to provide you some test-data: server-name: secura ID's: 3355 | 1759 | 5974 | 13593 | 4657 | 3727 If you need more test-data... just let me know Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1398517 Share on other sites More sharing options...
Barand Posted December 12, 2012 Share Posted December 12, 2012 I'm concatenating empty strings because I don't know if they are empty or not. When you use $pos[$q0."".$q1."".$q2."".$q3] How can you not know that "" is empty? Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1398814 Share on other sites More sharing options...
drunkenMonkey Posted December 12, 2012 Author Share Posted December 12, 2012 aaah... ok. So I should change that into this I guess: $pos[$q0.$q1.$q2.$q3] Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1398988 Share on other sites More sharing options...
Psycho Posted December 12, 2012 Share Posted December 12, 2012 aaah... ok. So I should change that into this I guess: $pos[$q0.$q1.$q2.$q3] Bingo! Don't feel too bad. I see people that do similar things a lot - especially when create a string concatenated from literal strings and variable - but if the value will end in a variable they always seem to tack on a . "" $query = "SELECT * FROM table WHERE id = " . $id . ""; instead of just $query = "SELECT * FROM table WHERE id = " . $id; or my preference $query = "SELECT * FROM table WHERE id = {$id}"; Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1398996 Share on other sites More sharing options...
drunkenMonkey Posted December 16, 2012 Author Share Posted December 16, 2012 (edited) Never to old to learn something new . Any other ideas on how to get the performance better? Edited December 16, 2012 by drunkenMonkey Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1399642 Share on other sites More sharing options...
Christian F. Posted December 16, 2012 Share Posted December 16, 2012 (edited) It seems that most of the processing time goes to fetching the details from the remote server, with the time fluctuating with about ±0.5 seconds: Function name Calls Call % Own time Total time Time % file_get_contents 8 8.24% 7.9249 s 7.9249 s 99.8% The calculatePos function takes the second place, and the rest is inconsequential: calculatePos 4 4.12% 10.367 ms 10.367 ms 0.13% So the best thing you can do to speed up this process, is to reduce the number of calls to file_get_contents and perhaps cache the data on your end. Also, you have quite a number of undefined offsets reported in your code, and I'm not sure the resulting array is quite what you expected: Notice: Undefined index: hits in /media/raid/Dropbox/htdocs/array_match.php on line 20 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 119 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 119 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 119 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 119 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 0 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 110 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 1 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 101 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 2 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 92 Notice: Undefined offset: 3 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 4 in /media/raid/Dropbox/htdocs/array_match.php on line 83 Notice: Undefined offset: 5 in /media/raid/Dropbox/htdocs/array_match.php on line 83drunkenMonkey | Strength: 1100 | Rank: Brigadier General q0: 1155 | q1: 2772 | q2: 3234 | q3: 3696 | q4: 4158 | q5: 4620 T11 | Strength: 1095 | Rank: Major q0: 1095 | q1: 2628 | q2: 3066 | q3: 3504 | q4: 3942 | q5: 4380 along | Strength: 1090 | Rank: Colonel q0: 1122 | q1: 2694 | q2: 3143 | q3: 3592 | q4: 4041 | q5: 4490 Ckt Five | Strength: 1090 | Rank: Major q0: 1090 | q1: 2616 | q2: 3052 | q3: 3488 | q4: 3924 | q5: 4360 Array ( [] => 0 ) Array ( [] => 0 ) Array ( [] => 0 ) Array ( [] => 0 ) This page was created in 7.4440829753876 seconds Edited December 16, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1399655 Share on other sites More sharing options...
drunkenMonkey Posted December 16, 2012 Author Share Posted December 16, 2012 (edited) Christian, thx for your post, it is very usefull. However I do not agree that most time gets into getting the data from the remote server. With a low number of hits, you are right, but if you increase the number of hits to 20 you'll see that most time will get in the calculatePos function wich actually can take up to 20 seconds for each call.... if we increase the number of hits even more to 25 or 30, the scripts times out... However having another look at my code, I can reduce the number of calls to the remote server by getting the next line out of the function: $ranksArray = json_decode(file_get_contents('http://e-sim.org/apiRanks.html'),true); I do this call for every player, but the answer from the server is always the same. So I only need to do this call once! Edited December 16, 2012 by drunkenMonkey Quote Link to comment https://forums.phpfreaks.com/topic/271491-find-match-between-2-arrays/#findComment-1399701 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.