creating an array in a class PHP -
this question has answer here:
- php parse/syntax errors; , how solve them? 11 answers
i trying complete objective homework assignment , im running issues. these instructions given me:
create class named daysofweek. include array of 7 days of week member of class. include function member of class when called, displays contents of array. create object , call function.
my textbook "w3schools" , im finding little difficult understand complete task.
php
class daysofweek{ var $days = array("monday", "tuesday", "wednesday", "thursday". "friday"); function showarray(){ $arrlength = count($days); ($x = 0, $x < $arrlength, $x++){ echo $days[$x]; echo "<br>"; } } }
this code have written. way believe have written extent of:
i created class called daysofweek. inside class defined var $days array of strings, each string being day of week. have function called showarray in theory loop through array display each day of week. create variable called $arrlength "count" indexes of array give me length of array. have "for loop" loop through array , echo each index of array according number $x is. if $x 0 should print "monday"....
two major issues i'm having:
i getting error: parse error: syntax error, unexpected ')', expecting ';' in c:\xampp\htdocs\program-05\program05.php on line 71
line 71 this: for ($x = 0, $x < $arrlength, $x++){
second thing, if wasn't getting error, i'm not code correct , complies instructions. least bit confused how classes work, after reading several things. there's syntax i've seen used in examples cant figure out does.......
what issue code?
($x = 0; $x < $arrlength; $x++)
note semi-colons
Comments
Post a Comment