473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

class method to compare two arrays fails - stumped

/*--------------------------------------------------------------------------------------------------------------------------------
Parameters:
$formField1: The name of the first array
$formField2: The name of the second array
$formField1CompareWith: String to use as my comparison basis for first
array. Defaults to using $val unless it's 'key'
$formField2CompareWith: String to use as my comparison basis for
second array. Same default as $formField1CompareWith
$match: Boolean to look for exact key or value match (default will
compare if instances compare true for both array)
---------------------------------------------------------------------------------------------------------------------------------*/
function isValidArrayCompare($formField1, $formField2,
$formField1CompareWith = '', $formField2CompareWith = '', $match = '')
{
// BOOLEAN TO COMPARE DIFFERENT FORM ELEMENT ARRAYS TOGETHER
reset($this->post);
if (!$formField1 && !$formField2) return false; // BLANK PARAMETERS
if (!in_array($formField1, array_keys($this->errorMsgObjArray)) &&
!in_array($formField2, array_keys($this->errorMsgObjArray))
) return false; // NOT IN ERROR MESSAGE OBJECT ARRAY
if (!in_array($formField1, array_keys($this->post)) &&
!in_array($formField2, array_keys($this->post))
) return false; // NOT IN GET/POST COLLECTION
$hasFoundValFormField1 = false;
if (strcmp(strtolower($formField1CompareWith), 'key') == 0 &&
strcmp(strtolower($formField2CompareWith), 'key') == 0) {
// KEY TO KEY ARRAY COMPARISON
if (@sizeof($this->post[$formField1]) > 0) { // FIRST ARRAY HAS KEYS
$hasFoundValFormField1 = true; $hasFoundValFormField2 = true;
foreach ($this->post[$formField1] as $key) {
if (@!in_array($key, array_keys($this->post[$formField2]))) { //
MATCHING KEY FOUND IN SECOND ARRAY
$hasFoundValFormField2 = false;
break;
}
}
}
} elseif (strcmp(strtolower($formField1CompareWith), 'key') == 0) {
// KEY TO VAL ARRAY COMPARISON
if (@sizeof($this->post[$formField1]) > 0) { // FIRST ARRAY HAS KEYS
$hasFoundValFormField1 = true; $hasFoundValFormField2 = true;
foreach ($this->post[$formField1] as $key) {
if (@!in_array($key, array_values($this->post[$formField2]))) { //
MATCHING VAL TO KEY FOUND IN 2ND ARRAY
$hasFoundValFormField2 = false;
break;
}
}
}
} elseif (strcmp(strtolower($formField2CompareWith), 'key') == 0) {
// VAL TO KEY ARRAY COMPARISON
if (@sizeof($this->post[$formField1]) > 0) { // SECOND ARRAY HAS KEYS
$hasFoundValFormField1 = true; $hasFoundValFormField2 = true;
foreach ($this->post[$formField1] as $key => $val) {
if (!$key[$val] || strlen($key[$val]) == 0) {
$hasFoundValFormField2 = false;
break;
}
}
}
} else {
// VAL TO VAL ARRAY COMPARISON
foreach ($this->post[$formField1] as $key => $val) {
if ($val && strlen($val) > 0 && !empty($val)) {
$hasFoundValFormField1 = true; $hasFoundValFormField2 = true;
if (@!in_array($val, array_values($this->post[$formField2]))) { //
MATCHING VAL FOUND IN SECOND ARRAY
$hasFoundValFormField2 = false;
break;
}
}
}
}
if ($hasFoundValFormField1 && $hasFoundValFormField2) return true;
return false;

}
My class method isValidArrayCompare will be comparing two arrays found
within the form post (passed into the class becoming $this->post). The
method has to have the following conditions:

1) Both arrays can be enumerative or associative, or one can be
enumerative and the other associative

2) Both arrays have to be able to be compared either by key-to-key,
key-to-val, val-to-key, or val-to-val

I have run into snags when you have this unique case:

Array A comes from a checkbox group and thus is not only enumerative,
but DYNAMIC as well (that is, it will only have values you checked
prior and that's all!); Array B comes from a group of dropdowns; each
dropdown down is given the same name but its key is the corresponding
value of the checkbox to the left (like $myCheckbox[0] => 'A' maps to
$myDropdown['A'] => 5). I need to be sure that the comparison will be
either true or false depending on if the value of Array A is found as
a key-with-a-value in Array B, AND if the key-with-a-value in Array B
exists as a value in Array A.

That's just THAT case. There will be a WHOLE lot more variances, but
the 2 rules above will always be true. I thought my method would cover
them all but alas, it fails on the Array A - Array B scenario if I
check more of Array A than I select of Array B for each Array A
checkbox.

You can see why I want to find an out-of-the-box solution for form
validation! >:(

Phil
Jul 17 '05 #1
0 2694

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Dan | last post by:
Hello, I have trouble with class calling. I am calling getvolume() with succes in the function CreateCircle but it do not want to call it in ShowCircle() function. I am staying in the same...
16
by: Dennis | last post by:
I have a class named "myclass" and an arraylist containing elements of type "MyClass". I want to get the value of a property of "MyClass" (a string type) for one of the arraylist elements. I...
8
by: rithish | last post by:
I am on IE 6. I was trying out a simple xmlhttp function that send GET/POST requests. However, IE throws an 'unspecified error' when I call the 'setRequestHeader' method. The function that I am...
5
by: Oleg Subachev | last post by:
Is there other way of comparing two byte arrays than iterating through the two and compare individual bytes ? Oleg Subachev
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
3
by: Fir5tSight | last post by:
Hi All, I have two identical PDF files, say file1 and file2. I used an API package to extract the bitmap in each PDF file, say bitmap1 (in file1) and bitmap2 (in file2). Since the bitmaps are...
1
by: stromhau | last post by:
Hi, I have made a few classes in c++. They somehow cooperate doing some 3d stuff. Basically it is a moving camera acting as a flight, i have placed a lot of objects around the scene together with...
7
by: Yen Kwoon | last post by:
Note: This problem is related to gcc but after some back and forth in group gnu.gcc.help it seems to have morph into more of a c++ specificiation question, hence the transplanting to this group. ...
6
by: Patient Guy | last post by:
I am a newcomer to using PHP but not to programming (C, C++, Javascript). I am playing around with classes and wanted to make a function that has a method simply for producing either plain text...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.