1. 程式人生 > >php實現無順序的連貫操作

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);