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 Using stripos: Starts with R

stage 6 challenge 1

I have this block of code that isn’t working correctly, but I can’t figure out the problem. It says that Broccoli and Cream Soda both start with R (my favorite letter), but they do not. Can you take a look? Can you change it so that it checks that the values in $var1 and $var2 start with R correctly?

index.php
<?php

    $var1 = "Cookie Dough";
    $var2 = "Chocolate";
    $initial = "r";

    if (stripos($var1,$initial) === 0 && stripos($var2,$initial) === 0) {

        echo $var1 . " and " . $var2 . " both start with " . $initial . ".";

    } else {

        echo "Either " . $var1 . " or " . $var2 . " doesn't start with " . $initial . "; maybe neither of them do.";

    }

?>

1 Answer

Hi,

Can you try to refresh it again, I think the question("Cookie Dough", "Chocolate") doesn't match with challenge codes. By refreshing, you should get right challenge codes that is seeking ("Broccoli", "Cream Soda")

Question:

I have this block of code that isn’t working correctly, but I can’t figure out the problem. It says that Broccoli and Cream Soda both start with R (my favorite letter), but they do not. Can you take a look? Can you change it so that it checks that the values in $var1 and $var2 start with R correctly?

We need to find "R" letter somewhere inside Broccoli and Cream Sode. Start with zero number

"Broccoli" = ["B", "r", "o", "c", "c", "o", "l", "i"];
              0     1    2    3    4    5    6   7

"Cream Soda"  = ["C", "r", "e", "a", "m", " ",  "S", "o", "d", "a"]
                  0    1    2    3    4    5     6    7    8    9

Now see the codes itself which says 0?