简体   繁体   English

PHP在数组内查找变量

[英]PHP find variable inside an array

I have an array called $this and in order to see what it contains i used print_r() and it happened to contain a lot of data. 我有一个名为$ this的数组,为了查看它包含的内容,我使用了print_r(),它恰好包含很多数据。 I need to know what variable produces the value for "user_id". 我需要知道哪个变量会产生“ user_id”的值。 It should be something like $this->user_id but i cant figure it out since its a lot of text. 它应该像$ this-> user_id之类的东西,但是由于文本很多,我无法弄清楚。 I would paste it here for you to see it but really, its too much. 我将其粘贴在此处供您查看,但实际上,它太多了。 So im pasting just a little extract: 所以即时贴只是一些提取物:

Am_Auth_User Object ( [idField:protected] => user_id [loginField:protected] => login [loginType:protected] => 0 [fromCookie:protected] => [userClass:protected] => User [plaintextPass:protected] => [session] => Zend_Session_Namespace Object ( [_namespace:protected] => amember_auth ) [user:protected] => [configPrefix:protected] => [protector:protected] => [di:protected] => Am_Di Object *RECURSION* ) [locale] => Am_Locale Object ( [locale:protected] => ja_JP ) [cacheBackend] => Zend_Cache_Backend_TwoLevels Object ( [_options:protected] => Array ( [slow_backend] => File [fast_backend] => Am_Cache_Backend_Array Object ( [_cache:protected] => Array ( [5dfbcb168a5b232b0ed52a1cb8cfb384] => 

Is there any php function that allows me to see all the variables i could use with $this array? 有没有允许我查看$ this数组可以使用的所有变量的php函数?

EDIT: I tried with 编辑:我尝试了

print_r(array_keys($this)); 

and

foreach(array_keys($this) as $name) {
        echo $name . "<br>";}

and

$a = array(1, 2, 3, 4, 5);
        print_r(array_map($this,$a));

But none of them produced anything. 但是他们都不生产任何东西。 Thank you. 谢谢。

Try this in place of just the print_r(): 试试这个代替print_r():

echo '<pre>'.print_r($your_variable, true).'</pre>';

That will make it easier to read; 那将使它更容易阅读; (the true parameter returns the print_r results as a string) (true参数以字符串形式返回print_r结果)

$this is an alias of whatever class it is called from. $this是调用它的任何类的别名。 so user_id would come from $this->user_id , which is just an alias of $user_id . 因此user_id将来自$this->user_id ,这只是$user_id的别名。 it is commonly a null variable at the top of the class, ie it has to be created by the class. 它通常是类顶部的null变量,即必须由类创建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM