I would like a quick help with this. Don't know where I am missing something. I am trying to add new schools into an array called Schools with a function, so that whenever someone passes in a value, it becomes part of the array for schools.
See the Code:
$schools = array("Johnson's College", "Oxford School of Ham");
echo count($schools);
function addSchools ($newSchool){
$schools[count($schools)] = $newSchool;
return $newSchool;
}
addSchool("Harvard Business School");
foreach($schools as $key){
echo $key;
}
The foreach statement is just to verify that the new school: "Havard Business..." was added. But it is giving an error.
Any to help fix that, so that when I use the foreach to loop through the array, I will see everything without error.
Thanks.
array_push(). See the documentation$schoolsvariable. Read about scopes.