note 67567 added to function.implode
| From: | kamil at kube dot org | Date: | Thu, 08 Jun 2006 20:28:38 +0000 |
| Subject: | note 67567 added to function.implode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-113905@lists.php.net to get a copy of this message | ||
Got class instances stored in an array? Implode them using implode_class_member:
<?
class FooBar {
private $iFoo;
private $sBar;
function getFoo() { return $this->iFoo; }
function getBar() { return $this->sBar; }
public function __construct( $iFoo, $sBar ) {
$this->iFoo = $iFoo;
$this->sBar = $sBar;
}
}
function implode_class_member( $sGlue, $aClasses, $sAccessorName ) {
if( !is_array( $aClasses ) || !count( $aClasses ) ) {
return NULL;
}
$aFoo = array();
foreach( $aClasses as $aClass ) {
$aFoo[] = eval( 'return $aClass->'.$sAccessorName.'();' );
}
return
implode( $sGlue, $aFoo );
}
$aCoo = array(
new FooBar( 1, 'foo' ),
new FooBar( 2, 'bar' ),
new FooBar( 9, 'coo' )
);
echo implode_class_member( ', ', $aCoo, 'getFoo' );
echo implode_class_member( ', ', $aCoo, 'getBar' );
?>
----
Server IP: 217.160.72.57
Probable Submitter: 85.176.13.88
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.implode.php
Edit -- http://master.php.net/note/edit/67567
Del: integrated -- http://master.php.net/note/delete/67567/integrated
Del: useless -- http://master.php.net/note/delete/67567/useless
Del: bad code -- http://master.php.net/note/delete/67567/bad+code
Del: spam -- http://master.php.net/note/delete/67567/spam
Del: non-english -- http://master.php.net/note/delete/67567/non-english
Del: in docs -- http://master.php.net/note/delete/67567/in+docs
Del: other reasons-- http://master.php.net/note/delete/67567
Reject -- http://master.php.net/note/reject/67567
Search -- http://master.php.net/manage/user-notes.php