简体   繁体   English

如何创建和访问PHP对象变量

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

OK So I figured it out :) It works how it should now thanks to your example. 好的,所以我想出了:)由于您的示例,它现在应该如何工作。

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

I actually didn't realize you could pass arrays through to the function, I Have not come across an example seeing that before, so I didn't know it was possible. 我实际上没有意识到您可以将数组传递给该函数,之前我还没有遇到过看到它的示例,所以我不知道这是可能的。 I thought you could only pass strings through with a comma separating them, so thank you. 我以为您只能用逗号隔开字符串,所以谢谢。

You should probably read the manual . 您可能应该阅读该手册

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