Michdd Posted June 6, 2009 Share Posted June 6, 2009 I have this array: $numberMaps = array( '0011110001000010100000010100001000111100', '0010000101000001111111110000000100000001', '0100001110000101100010011001000101100001', '0100001010000001100100011001000101101110', '0001110000100100010001001111111100000100', '1111001010100001101000011010000110011110', '0011111001010001100100011001000110001110', '1000000010000011100011001011000011000000', '0110111010010001100100011001000101101110', '0111000110001001100010011000101001111100' ); I figure it would be easier to accomplish what I need to do by writing a simple php script rather than doing it by eye.. Basically I need to find out how short I can shorten those strings in the array so that they're still unique. Quote Link to comment https://forums.phpfreaks.com/topic/161172-solved-comparing-elements-of-an-array/ Share on other sites More sharing options...
laffin Posted June 6, 2009 Share Posted June 6, 2009 Looks like binary sequences, convert to decimal (floats) or hexadecimal or other number base. Quote Link to comment https://forums.phpfreaks.com/topic/161172-solved-comparing-elements-of-an-array/#findComment-850488 Share on other sites More sharing options...
Michdd Posted June 6, 2009 Author Share Posted June 6, 2009 Nevermind, I solved it. Since just 8 numbers would be good enough (since it relates to 1 full loop somewhere else in my code).. I just did this: $numberMaps = array( '0011110001000010100000010100001000111100', '0010000101000001111111110000000100000001', '0100001110000101100010011001000101100001', '0100001010000001100100011001000101101110', '0001110000100100010001001111111100000100', '1111001010100001101000011010000110011110', '0011111001010001100100011001000110001110', '1000000010000011100011001011000011000000', '0110111010010001100100011001000101101110', '0111000110001001100010011000101001111100' ); for($i = 0;$i < count($numberMaps);$i++) { $newArr[] = substr($numberMaps[$i], 0, ; } for($i = 0;$i < count($newArr);$i++) { for($j = 0;$j < count($newArr)-1;$j++) { if($newArr[$i] == $newArr[$j] && $j != $i) { echo 'Found a match..' . $i . ' and ' . $j; } } } No matches. Quote Link to comment https://forums.phpfreaks.com/topic/161172-solved-comparing-elements-of-an-array/#findComment-850491 Share on other sites More sharing options...
.josh Posted June 6, 2009 Share Posted June 6, 2009 foreach ($numberMaps as $num) { $num = substr($num,0,; if ($t[$num]) { echo "match found"; break; } else { $t[$num] = ''; } } Quote Link to comment https://forums.phpfreaks.com/topic/161172-solved-comparing-elements-of-an-array/#findComment-850561 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.