tqla Posted August 31, 2010 Share Posted August 31, 2010 Hello. Can someone show the syntax to echo the variable from the array below that is showing "2010-08-31 23:19"? I need to grab that date and use it elsewhere in my script. Thanks. array(19) { ["name"]=> string( "com_jumi" ["params"]=> array(0) { } ["mainframe"]=> &object(JSite)#2 (6) { ["_clientId"]=> int(0) ["_messageQueue"]=> array(0) { } ["_name"]=> string(4) "site" ["scope"]=> string( "com_jumi" ["_errors"]=> array(0) { } ["requestTime"]=> string(16) "2010-08-31 23:19" } Link to comment https://forums.phpfreaks.com/topic/212232-help-getting-variable-from-array/ Share on other sites More sharing options...
Psycho Posted August 31, 2010 Share Posted August 31, 2010 If I am reading that correctly you would reference it thusly: echo $arrayName['mainframe']['requestTime']; //Output: 2010-08-31 23:19 Link to comment https://forums.phpfreaks.com/topic/212232-help-getting-variable-from-array/#findComment-1105864 Share on other sites More sharing options...
Pikachu2000 Posted August 31, 2010 Share Posted August 31, 2010 You should be able to access it like any other array element: $array_name['requestTime'] Link to comment https://forums.phpfreaks.com/topic/212232-help-getting-variable-from-array/#findComment-1105865 Share on other sites More sharing options...
tqla Posted September 1, 2010 Author Share Posted September 1, 2010 Thanks. Link to comment https://forums.phpfreaks.com/topic/212232-help-getting-variable-from-array/#findComment-1105889 Share on other sites More sharing options...
tqla Posted September 1, 2010 Author Share Posted September 1, 2010 So in this case (below) what is the $arrayName? I've tried com_jumi but it did not work. I know how to get array elements but this has me beat. Array ( [name] => com_jumi [params] => Array ( ) [mainframe] => JSite Object ( [_clientId] => 0 [_messageQueue] => Array ( ) [_name] => site [scope] => com_jumi [_errors] => Array ( ) [requestTime] => 2010-09-01 00:39 ) Link to comment https://forums.phpfreaks.com/topic/212232-help-getting-variable-from-array/#findComment-1105893 Share on other sites More sharing options...
AbraCadaver Posted September 1, 2010 Share Posted September 1, 2010 It's a property of an object in an array, so: echo $array['mainframe']->requestTime; Link to comment https://forums.phpfreaks.com/topic/212232-help-getting-variable-from-array/#findComment-1105894 Share on other sites More sharing options...
AbraCadaver Posted September 1, 2010 Share Posted September 1, 2010 So in this case (below) what is the $arrayName? I've tried com_jumi but it did not work. I know how to get array elements but this has me beat. Array ( [name] => com_jumi [params] => Array ( ) [mainframe] => JSite Object ( [_clientId] => 0 [_messageQueue] => Array ( ) [_name] => site [scope] => com_jumi [_errors] => Array ( ) [requestTime] => 2010-09-01 00:39 ) The only way to get the output you posted is by doing var_dump($something); so whatever $something is, is what $array is in my example. Link to comment https://forums.phpfreaks.com/topic/212232-help-getting-variable-from-array/#findComment-1105895 Share on other sites More sharing options...
tqla Posted September 1, 2010 Author Share Posted September 1, 2010 AbraCadaver, I used: print_r ( get_defined_vars() ); Link to comment https://forums.phpfreaks.com/topic/212232-help-getting-variable-from-array/#findComment-1105896 Share on other sites More sharing options...
AbraCadaver Posted September 1, 2010 Share Posted September 1, 2010 No, that won't give you that output, but try: echo $mainframe->requestTime; Link to comment https://forums.phpfreaks.com/topic/212232-help-getting-variable-from-array/#findComment-1105897 Share on other sites More sharing options...
tqla Posted September 1, 2010 Author Share Posted September 1, 2010 BOOM! That works! Thanks AbraCadaver! Link to comment https://forums.phpfreaks.com/topic/212232-help-getting-variable-from-array/#findComment-1105898 Share on other sites More sharing options...
AbraCadaver Posted September 1, 2010 Share Posted September 1, 2010 BOOM! That works! Thanks AbraCadaver! Cool, just to clarify, the output in your original post is from a var_dump() The follow-ups are print_r(). I quoted one and didn't even look at it Link to comment https://forums.phpfreaks.com/topic/212232-help-getting-variable-from-array/#findComment-1105904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.