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 trial

PHP Enhancing a Simple PHP Application Adding Search: Model Introducing the strpos Function

Nthulane Makgato
PLUS
Nthulane Makgato
Courses Plus Student 19,602 Points

Introducing strpos

I've been struggling with this simple quiz. I would have thought that the answer was 6 if you consider "Chocolate", "C" being 0 and counting from there.

<?php

    $flavors = array("Chocolate","Vanilla","Strawberry","Cookie Dough");
    echo strpos($flavors[1],"a");

?>

Thank you in advance.

2 Answers

The answer is 1 because $flavors[1] = "vanilla", chocolate is $flavors[0]

Nthulane Makgato
PLUS
Nthulane Makgato
Courses Plus Student 19,602 Points

Ah... thank you very much George, I thought it was something that simple.

you're welcome, can you set the answer as "best answer" please :)