There is a fairly popular program (I forgot the name) that generates triangles where there is a question or answer on each side, and each triangle fits together, so the answer to one triangle corresponds to the question of the other, and when correctly composed, it creates a large (usually a regular hexagon).
I am trying to write a script where $t
is a 2D array containing maps:
$t = array(); // $t['1'] represents the 'center' triangle in this basic example $t['1'] = array( '1', // One side of T1, which is an answer '3-1', // Another side, this is a question '2+1' // Final side, another question ); // These cards go around the outside of the center card $t['2'] = array( '2-1' // This is a question on one side of T2, the other sides are blank ); $t['3'] = array( '2' // This is an answer on one side of T3, the other sides are blank ); $t['4'] = array( '3' // This is an answer on one side of T4, the other sides are blank );
What now needs to be done, say, for example, "T1-S1 corresponds to T2, T1-S2 corresponds to T3, T1-S3 corresponds to T4." I have tried, and what I still have is below:
foreach ($t as $array) { foreach ($array as $row) { $i = 0; while ($i <= 4) { if(in_array($row, $t[$i])){ echo $row . ' matches with triangle ' . $i . '<br />'; } $i++; } } }
Note: the above code is for the simplified version, where all issues were "resolved", and it was just a coincidence with the two sides.
After running my code, I get this output:
1 matches with triangle 1 1 matches with triangle 2 2 matches with triangle 1 2 matches with triangle 3 3 matches with triangle 1 3 matches with triangle 4 1 matches with triangle 1 1 matches with triangle 2 2 matches with triangle 1 2 matches with triangle 3 3 matches with triangle 1 3 matches with triangle 4
The problem is that $row
tells me only the side of the triangle, not the actual triangle. So my question is this:
How to make my script work so that it displays "ta-Sb matches Tc-Sd", where a is the triangle, b is the side, c is the triangle that matches, d is the side with which it matches, if we assume that in each array the side values ββare in order?
Hope the question is clear, but feel free to ask any questions.
Furthermore, ideally, when it corresponds to Ta-Sb with Tc-Sd
, it should not correspond to Tc-Sd with Ta-Sb
. Is this also possible?