Jump to content

[SOLVED] Assistance with getting info out of an array


Chris@ETI

Recommended Posts

I have a variable that has an array assigned to it.  The output of print_r(array_values($var)) gives me the following:

 

Array ( [0] => stdClass Object ( [userid] => 19 [instanceid] => 5 [fullname] => GD&T Fundamentals Course [contextid] => 41 [id] => 5 ) [1] => stdClass Object ( [userid] => 19 [instanceid] => 7 [fullname] => GD&T Fundamentals Certification Exam [contextid] => 70 [id] => 7 ) )

 

What I need to do from here is to go through the array, and pull out the values for the two [fullname] areas.  I can't seem to figure out how to do this, with any of the array commands.  I'm thinking that this is a multi-dimensional array, but all the examples I have found on how to pull data out of a multi-dimensional array don't seem to work in my case.

 

I'm new to PHP, so I'm sure I'm just running into "beginner's block".  If someone could tell me how I would pull the first fullname value out of the array and assign it to a variable, I could most likely figure out the rest of the code from there.

I believe so.  At one point I was able to output the contents of the array in a much easier to read format, but I can't remember how I did that either.

 

The array contains a list of the courses that the user is assigned to on our e-learning site. In the array i posted, the user is part of two courses.  If I do an print_r(array_keys($var)) I get the following:

 

Array ( [0] => 5 [1] => 7 )

 

Those two key/values correspond to the id #'s for my courses.  The rest of the data is information regarding each course.  I just can't figure out how to get to it.

 

I hope that was helpful, in some way, shape, or form.

The output of var_dump is:

 

array(2) { [5]=> object(stdClass)#421 (5) { ["userid"]=> string(2) "19" ["instanceid"]=> string(1) "5" ["fullname"]=> string(24) "GD&T Fundamentals Course" ["contextid"]=> string(2) "41" ["id"]=> int(5) } [7]=> object(stdClass)#420 (5) { ["userid"]=> string(2) "19" ["instanceid"]=> string(1) "7" ["fullname"]=> string(36) "GD&T Fundamentals Certification Exam" ["contextid"]=> string(2) "70" ["id"]=> int(7) } }

 

As for what class I'm using, I have to admit I'm not sure exactly what you are looking for.  If you could clarify, I'd be happy to answer.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.