-
October 26th, 2010, 04:00 PM
#1
Way to have certain fields ignored in compare
I have two fields that are equal to each other, except for one field. Is there a way to get the comparison to ignore that field? It's an iterator pointer, the iterator position should not matter when comparing objects to each other.
-
October 26th, 2010, 04:22 PM
#2
Re: Way to have certain fields ignored in compare
I'm sorry, can you be more specific? Some code to help us understand what you are doing?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
October 27th, 2010, 09:33 AM
#3
Re: Way to have certain fields ignored in compare
Code:
class foo {
private $_mapping = array(1,2,3);
private $_position = 0;
public function rewind() {
$this -> _position = 0;
}
public function current() {
return $this -> _mapping[$this -> _position];
}
public function key() {
return $this -> _position;
}
public function next() {
++$this -> _position;
}
public function valid() {
return isset($this -> _mapping[$this -> _position]);
}
}
$test = new foo();
$test2 = new foo()
foreach($test as $i){}
echo '' . $test == $test2; //false because _position is in different places, but the actual content in the same
-
October 27th, 2010, 10:54 AM
#4
Re: Way to have certain fields ignored in compare
I'm sorry but without any explanation, this still isn't helping. Let me try to explain what isn't exactly understandable...
Originally Posted by ninja9578
I have two fields that are equal to each other, except for one field.
- Two equal minus one results in none equal. So what exactly are you comparing?
- What do you mean by field? Are these <input> values passed to the server?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
October 27th, 2010, 02:20 PM
#5
Re: Way to have certain fields ignored in compare
The mapping members are exactly the same, the _position item is different, but does not affect the "value" of the object publicly. I want the $test == $test2 to be true.
I want it be be the equivalent of this
Code:
bool operator == (const foo & $bar){
return $bar -> _mapping == $this -> _mapping;
}
Last edited by ninja9578; October 27th, 2010 at 02:24 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|