Developers challenge
Posted: Thu Apr 27, 2006 4:50 pm
Ok, so ever suggests the method I use...wins a million dollars and the respect and admiration of the community for one day 
Just kidding of course...but it's an interesting problem...and I'll be sure to add your name and credits to the function comments
I have a function, which is basically scanning one array and comparing it's values to another array and conducting a trivial multi-field comparison...
Like a SQL:
Only I'm using native PHP and arrays...
The way I match criteria and conclude an answer is by comparing each item against another and the result of that basic test is stored or pushed onto an array...basic boolean test will always yield TRUE or FALSE(1 or 0)...
At the end of looping I then compare the number of elements in the array which holds the indivual results to the SUM of all values in the array which holds results...
By seeing the above it becomes obvious that a quick way to determine if each result was TRUE (ultimately returning TRUE as each criterion was met) is to SUM the values and compare that to the count() of the array...
This is how I've done it thus far...but I am convinced there is a better way...by I am brain dead for the day...at least when working on this...
So what do you think?
Can you come up with a more effective & efficient solution?
I've implemented a second solution, but I have to benchmark it first...
I'm curious what someone else can come up with...
Cheers
Just kidding of course...but it's an interesting problem...and I'll be sure to add your name and credits to the function comments
I have a function, which is basically scanning one array and comparing it's values to another array and conducting a trivial multi-field comparison...
Like a SQL:
Code: Select all
SELECT * FROM table WHERE name = "Bob" and age = 97The way I match criteria and conclude an answer is by comparing each item against another and the result of that basic test is stored or pushed onto an array...basic boolean test will always yield TRUE or FALSE(1 or 0)...
At the end of looping I then compare the number of elements in the array which holds the indivual results to the SUM of all values in the array which holds results...
Code: Select all
$arr[0] = 1; // Username test
$arr[1] = 1; // Postal test
$arr[2] = 1; // Address test
...This is how I've done it thus far...but I am convinced there is a better way...by I am brain dead for the day...at least when working on this...
So what do you think?
Can you come up with a more effective & efficient solution?
I've implemented a second solution, but I have to benchmark it first...
I'm curious what someone else can come up with...
Cheers