Forum Moderators: coopster

Message Too Old, No Replies

accessing information in a multidimensional array

giving me a headache

         

londrum

10:19 am on Oct 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hello. im wondering (hoping!) that someone with more brains than me can work this out. spent half a day on it and i cant figure it out. im not too good when it comes to arrays

i've got a forum-type thing that displays a load of posts. and each post has an ID number. i need to access that number, so i can use it in my template.

i have figured out (using get_defined_vars) that these numbers are definitely contained in a big array, which presumably i can access in my script, but it is a big multi-dimensional array, and i can't work out what to target.

here is a scaled-down version of what i can get using get_defined_vars.
the number that i need to access is the 'IDDD' number

$arr = array

(


[this] => template Object

(


[_tpldata] => Array

(


[blogrow] => Array

(


[0] => Array

(


[USER_ID] => 128

[IDDD] => 127

)

coopster

12:31 pm on Oct 29, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Looks like it may be a template class and hopefully that is a public variable. If so, the class structure is building that multi-dimensional array which I tried to replicate in a mini class to demonstrate how to access the array index you want:

class template { 
public $_tpldata = array(
'blogrow' => array(
'USER_ID' => 128,
'IDDD' => 127
)
);
}
$arr = array('this' => new template());
print '<pre>';
print_r($arr);
print "\nIDDD is : ";
print $arr['this']->_tpldata['blogrow']['IDDD'];
print '</pre>';
exit;

londrum

2:01 pm on Oct 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



coopster you are a genius, thanks. i got it working from that.
i was trying stuff like
$arr['this']['_tpldata']['blogrow'][0]['IDDD'];

i better do some reading on that class stuff