Jump to content

[SOLVED] Comparing elements of an array


Michdd

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/161172-solved-comparing-elements-of-an-array/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.