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 trialAayush Masiwal
Courses Plus Student 895 Pointsarray_slice
<?php
$input = array("a", "b", "c", "d", "e");
$output = array_slice($input, -2, 1); // returns "d"
?>
i am not getting how this function work ?
1 Answer
Kane Simmons
14,206 PointsHey Aayush, what the array_slice function takes the array you assign to it "$input" and takes a piece of it. It does this with the second value assigned , the offset, which determines how far form the start (positive value) or the end (negative value). The next value is the length of the sequence, a.k.a. how many of the numbers it will include, so in this case, your array is $input, your offset is -2, and your length is 1, so your starting 2 from the end and only including 1 number "d". Lengthy answer I know but I hope this helps!
Aayush Masiwal
Courses Plus Student 895 PointsAayush Masiwal
Courses Plus Student 895 Pointsu make this simple for me thanx