loop through variables

Posted on 2012-09-07
Last Modified: 2012-09-08
four variables

2-4 possibilities for each variable

want to loop through each


varX.possbilityX !=varX.possbilityX

in this example there are
I think 100 different possibilities total
Question by:rgb192
    LVL 42

    Expert Comment

    by:Rob Jurd, EE MVE
    what are you trying to achieve by this?
    LVL 17

    Assisted Solution

    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?
    LVL 107

    Assisted Solution

    by:Ray Paseur
    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
    LVL 33

    Accepted Solution

    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.

    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 />";
    for (i=0; i < out1.length; i++) {

    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.

    Author Closing Comment

    thanks for guiding me in  a good direction

    this led me to ask a better quesiton

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now