I'm experimenting with PHP and object oriented programming in PHP. When I try to run the following displayArray
function, it does not display the line at all. Does anyone know what I'm doing wrong?
<?php
class Student
{
var $name;
var $arr;
function Student()
{
$this->name = "bob";
$this->addnametostring("Hello there ");
$this->arr = array();
for($i=0; $i<30; $i++) {
$arr[$i] = rand(0,100);
}
}
function addnametostring($s)
{
$s.= " " . $this->name;
echo "$s <br>";
}
function displayArray($amt)
{
foreach($this->arr as $key) {
//why is this not working
echo "<br>hello: ".$key;
}
}
}
$student = new Student;
echo "<br>";
$student->displayArray(20);
?>