15-12-2008, 10:15 PM
Tu dois coder toi même ta méthode equal. Voici un exemple en Actionscript, mais c'est la même chose en PHP.
Code PHP :
<?php
package
{
public class CollectionItem
{
private var _name:String;
private var _value:Number;
public function CollectionItem( name:String, value:Number )
{
_name = name;
_value = value;
}
public function getName():String
{
return _name;
}
public function getValue():Number
{
return _value;
}
public function equal( o:CollectionItem ):Boolean
{
return ( o != null && this.getName() == o.getName() && this.getValue() == o.getValue() );
}
}
}
Code PHP :
<?php
package
{
public class Collection
{
private var _list:Array;
public function Collection()
{
_list = new Array();
}
public function add( o:CollectionItem ):void
{
_list.push( o );
}
public function remove( o:CollectionItem ):void
{
var index:int = _list.indexOf( o );
if( index >= 0 )
{
_list.splice( index, 1 );
}
}
public function contains( o:CollectionItem ):Boolean
{
for each( var i:CollectionItem in _list )
{
if( o.equal( i ) )
{
return true;
}
}
return false;
}
}
}