- var_dump: documentation ( source)
- implode: documentation ( source)
<?php
class friendList {
private $friends;
public function __construct(array $names){
$this->friends = array();
if($names) foreach($names as $name) $this->addFriend($name);
}
public function addFriend($name) {
$this->friends[] = $name;
}
public function getFriends() {
return $this->friends;
}
}
$friends = new friendList(array('Eric','Dan','Lisa'));
function funtimes($friends) {
echo implode(", ", $friends->getFriends()) . "\n";
$friends->addFriend('John');
}
funtimes($friends);
var_dump($friends);
$funtimes2 = function() use ($friends) {
echo implode(", ", $friends->getFriends()) . "\n";
$friends->addFriend('Mark');
};
$funtimes2();
var_dump($friends);