簡體   English   中英

如何創建和訪問PHP對象變量

[英]How do I Create and Access PHP Object Variables

好的,所以我想出了:)由於您的示例,它現在應該如何工作。

class Test_Class { 
    public function Test_Function_1(array $Test_Array_1) {
        echo'TF1_Var_1 = '. $Test_Array_1['TF1_Var_1'] . '<br> <br>';
    }
    public function Test_Function_2($Test_Selector_2, array $Test_Array_2) {
        echo'Test_Selector_2 = '. $Test_Selector_2 . '<br>';
        echo'TF2_Var_1 = '. $Test_Array_2['TF2_Var_1'] . '<br>';
    }
}

$Test_Run = new Test_Class();
$Test_Run->Test_Function_1([ 'TF1_Var_1' => 'TF1_Val_1', 'TF1_Var_2' => 'TF1_Val_2', 'TF1_Var_3' => 'TF1_Val_3' ]);
$Test_Run->Test_Function_2('TF2_Selector_Data' , [ 'TF2_Var_1' => 'TF2_Val_1', 'TF2_Var_2' => 'TF2_Val_2', 'TF2_Var_3' => 'TF2_Val_3' ]);

我實際上沒有意識到您可以將數組傳遞給該函數,之前我還沒有遇到過看到它的示例,所以我不知道這是可能的。 我以為您只能用逗號隔開字符串,所以謝謝。

您可能應該閱讀該手冊

class TestClass { 
    public function test1(array $array) {
        var_dump($array);
    }
    public function test2($selector, array $array) {
        var_dump($selector, $array);
    }
}

$test = new TestClass();
$test->test1([ 'TF1_Var_1' => 'TF1_Val_1', 'TF1_Var_2' => 'TF1_Val_2', 'TF1_Var_3' => 'TF1_Val_3' ]);
$test->test2("TF2_Selector", [ 'TF1_Var_1' => 'TF1_Val_1', 'TF1_Var_2' => 'TF1_Val_2', 'TF1_Var_3' => 'TF1_Val_3' ]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM