<?php /*顯示原始碼*/ $file=__FILE__; require("src.php"); ?>
<h2>如何在php內用類似jQuery傳obj的方式傳不定量的預設值給Object/Function</h2>
<?php
class Bot{
    public 
$vars = [
    
'base_url'=>'https://api.telegram.org/',
    
'token'=>'預設值'
  
];
    function 
__construct($init){
    
//$this->token = (empty($init->token)) ? "" : $init->token;
    
$this->vars=array_merge($this->varsarray_intersect_key($init,$this->vars));
    }
}
$bot = new Bot([
  
"token"=>"覆蓋預設值",
  
"abc"=>"test"
]);
 echo 
"<pre>" print_r($bot->vars,1);
?>

如何在php內用類似jQuery傳obj的方式傳不定量的預設值給Object/Function

Array
(
    [base_url] => https://api.telegram.org/
    [token] => 覆蓋預設值
)