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

confused about why array_key_exists was used here

public function getCombinedIngredients(){ $ingredients = array(); foreach ($this->recipes as $recipe){ foreach ($recipe->getIngredients() as $ing){

         $item = $ing["item"];
         if(strpos($item,",")){ 
             $item  = strstr($item,',',true); // gets rid of comma before the output
         }
         if(strstr($item,-1) == 's' && array_key_exists(rtrim($item,"s"),$ingredients)){


             $item = rtrim($item,"s");
         }else if(array_key_exists($item."s",$ingredients)){
             $item .="s";
         }
         $ingredients [$item] = array(

             $ing["amount"],
             $ing["measure"]
         );
     }
 }
 return $ingredients;

}

} hi why array_key_exist was used here cause i though we are looking through value I though array_value_exsits would make more sense.