php实现无顺序的连贯操作

class testcoh{
   
   public $arr;
   
   public function __construct($str ='')
   {
      $this -> arr = array($str);
   }
   
   public function push($str){
      array_push($this -> arr,$str);
      return $this;
   }
   
   public function unshift($str){
      array_unshift($this -> arr,$str);
      return $this;
   }
   
}
//引入连贯操作类
require(dirname(__FILE__).'/includes/coherent.php');

$coh = new testcoh('1');
$data = $coh -> push('a') -> unshift('b') -> arr;
echo "<pre>";
print_r($data);

猜你喜欢

转载自blog.csdn.net/qq_38085855/article/details/81503023