Create a method in the following class to return the category using its key?


class femon{

 protected $name = 'TenShops';

 protected static $categories = array(

  1 => 'fruits',

  2 => 'vegetables',

  4 => 'household',

  8 => 'toys',

  16 => 'bathroom',

  32 => 'kitchen',

  64 => 'livingroom',

  128 => 'hardware',

  256 => 'babycare',

 );
}

Train Asked on October 28, 2015 in PHP.
Add Comment
  • 1 Answer(s)
    
    protected function getCategory($id=1){
    if(array_key_exist(self::$categories[$id])){
      return self::$categories[$id];
    }else{
      return false;
    }
    
    
    Train Answered on October 28, 2015.
    Add Comment

    Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.