在没有循环或条件的情况下打印1到1000 – 在PHP中

here开始的想法 – 这次你只能使用PHP.
这有可能吗?
这是一个基于PHP重载的有趣oo解决方案:
class thousand_printer {
   public function __construct() {
      $this->print1();
   }

   public function __call($method,$_) {
      $count = str_replace('print','',$method);
      echo "$count ";
      $this->{"print" . ++$count}();
   }

   public function print1000() {
      echo "1000\n";
   }
}

new thousand_printer;

我很高兴我的解决方案如此受欢迎.这是一个略微改进,提供了一些模块化:

class printer {
   public function __construct() {
      $this->print1();
   }
   public function __call($method,$method);
      echo "$count ";
      $this->{"print" . ++$count}();
   }
}

class thousand_printer extends printer {
   public function print1001() {}
}

new thousand_printer;

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...