1<?php
2class Person
3{
4 public $name;
5 public $age;
6
7 function birthday($age){
8 $age = $age + 1;
9 return $age;
10 }
11}
12
13$person1 = new Person();
14$person1->name = 'David';
15$person1->age = '23';
16
17$person2 = new Person();
18$person2->name = 'Nuno';
19$person2->age = '21';
20$person2->age = $person2->birthday($person2->age);
21
22$persons = array($person1, $person2);
23
24foreach ($persons as $person) {
25 echo 'My name is ' . $person->name . ' and i have ' . $person->age . " years old";
26 echo '<br>';
27}
28?>