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