in_array()函数不能正常工作

时间:2016-12-11 12:39:23

标签: php oop

我有一个任务是在OOP中表示5个HTML元素,所以我开始但在构造函数中我已经遇到了问题。我不知道这有什么问题。问题是函数in_array()无法正常工作。

htmlTags.php

<?php

   class htmlTags
   {
       public $tags = array('a', 'img', 'div', 'input', 'select');
       public $tag;
       public $num;

       function __construct($control)
       {
¨         if (in_array($control, $tags))
          {
            $this->num = 1;  
          }   
          else
          {
             $this->num = 0;  
          }
       }
   }

的index.php

<?php
  require_once('classes/htmlTags.php');

  $tag = new htmlTags('a');
  echo $tag->num;
 ?>

虽然&#34; a&#34;存在于数组$ tags中,每次我得到一个回声&#34; 0&#34;这应该意味着它不存在于数组中。

非常感谢您提前

0 个答案:

没有答案
相关问题