Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

loop through variables

Posted on 2012-09-07
5
Medium Priority
?
490 Views
Last Modified: 2012-09-08
four variables

2-4 possibilities for each variable


want to loop through each


var1(possbility1,possbility2,possbility3)
var2(possbility1,possbility2)
var3(possbility1,possbility2,possbility3,possbility4)
var4(possbility1,possbility2)

varX.possbilityX !=varX.possbilityX


in this example there are
I think 100 different possibilities total
0
Comment
Question by:rgb192
5 Comments
 
LVL 43

Expert Comment

by:Rob
ID: 38378901
what are you trying to achieve by this?
0
 
LVL 17

Assisted Solution

by:nanharbison
nanharbison earned 500 total points
ID: 38379172
I think here are only 48 possibilities-
3  x  2  x  4  x  2 = 48
Are you trying to figure out if any one of the 11 variables are the same?
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 500 total points
ID: 38379194
This part has me stumped:

varX.possbilityX !=varX.possbilityX

The problem with that statement is that in any programming language, it will be false.

Please post some test data examples and the expected output.  If we can see that, and you can explain the rules for filtering, I am sure we can help you implement the rules in PHP code.  Thanks, ~Ray
0
 
LVL 34

Accepted Solution

by:
Slick812 earned 1000 total points
ID: 38379734
greetings  rgb192, although the statements in your question do not make any sense to me in a "Code" meaning sort of way?  You say = "in this example there are, I think 100 different possibilities total " , not sure I follow your Math logic in that statement, if you have 4 containers (var1, var2, var3, var4) with 4 things in each one, then you have 16 things (possibilities) not 100.
Don't see any "Code" connection to PHP in your question as a variable would be made with =
$var1 = new stdClass(array('possbility1'=>10,'possbility2'=>20,'possbility3'=>30));

so I'm going to do this in javascript, which has some resemblance to your kind of code statements.

<script>
var var1 ={pos1:10, pos2:20, pos3:30};
var var2 ={pos1:12, pos2:20};
var var3 ={pos1:10, pos2:23, pos3:33, pos4:40};
var var4 ={pos1:14, pos2:20};
var out1 = ["NO MATCHS<br />"];

for (var n = 1; n < 4; n++) {
	var cnt = 0;
	var ob1 = eval("var"+n);
	for (var prop1 in ob1) {
		for (var c = n+1; c < 5; c++) {
			var ob2 = eval("var"+c);
			for (var prop2 in ob2) {
			if (ob2[prop2] == ob1[prop1]) {
				out1[cnt] = "var"+c+"."+prop2+" IS EQUAL TO "+"var"+n+"."+prop1+"<br />";
				++cnt;
				}
				}
			
			}
		}
	}

for (i=0; i < out1.length; i++) {
	document.write(out1[i]);
	}
</script>

Open in new window


I do NOT use your -
varX.possbilityX !=varX.possbilityX

"NOT equal to" test, instead I use an "equal to" test in line 15 of the code above

and it reads out the three var properties that are equal, from my browser -
var4.pos2 IS EQUAL TO var2.pos2
var2.pos2 IS EQUAL TO var1.pos2
var4.pos2 IS EQUAL TO var1.pos2

Hope this helps you, I only did this because using the javascript object properties is confusing and trying to get property names AND values from a enumeration of an object is kind of a Pain for me.

please ask questions if you need more information.
0
 
LVL 1

Author Closing Comment

by:rgb192
ID: 38379934
thanks for guiding me in  a good direction


this led me to ask a better quesiton
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_27858118.html
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question