Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialammarkhan
Front End Web Development Techdegree Student 21,661 Pointswhy is $this->instructions[] = $string?
This video is a little hard to understand, at video time 2:00, Alena create a function addInstruction
and set its inner body as following php $this->instructions[] = $string
, i am finding hard to understand that if instructions is a array then why put php $string
in front of it. Is she assigning a override of array to a single value which is string? also i am unable to understand $tags involvement in the video
1 Answer
Seth Kroger
56,413 Points$array[] = $something
is PHP shorthand for appending a new item to the array (much line JavaScript's array.push(something))
ammarkhan
Front End Web Development Techdegree Student 21,661 Pointsammarkhan
Front End Web Development Techdegree Student 21,661 PointsOh, this is great. Thanks!
ammarkhan
Front End Web Development Techdegree Student 21,661 Pointsammarkhan
Front End Web Development Techdegree Student 21,661 PointsSeth Kroger why are they using addTag, is it a setter or getter as i remember it, when setting getters and setters we need to use the word
php set
and
php get
`Seth Kroger
56,413 PointsSeth Kroger
56,413 PointsBecause $tags is a list. setTags() would be for setting the whole list of tags, while addTag() adds one to the current list.