Chris@ETI Posted June 9, 2009 Share Posted June 9, 2009 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. Link to comment https://forums.phpfreaks.com/topic/161557-solved-assistance-with-getting-info-out-of-an-array/ Share on other sites More sharing options...
gevans Posted June 9, 2009 Share Posted June 9, 2009 Is the array populated with two objects? Link to comment https://forums.phpfreaks.com/topic/161557-solved-assistance-with-getting-info-out-of-an-array/#findComment-852531 Share on other sites More sharing options...
Chris@ETI Posted June 9, 2009 Author Share Posted June 9, 2009 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. Link to comment https://forums.phpfreaks.com/topic/161557-solved-assistance-with-getting-info-out-of-an-array/#findComment-852550 Share on other sites More sharing options...
gevans Posted June 9, 2009 Share Posted June 9, 2009 can you show me the results of var_dump($var) and post the class you're using Link to comment https://forums.phpfreaks.com/topic/161557-solved-assistance-with-getting-info-out-of-an-array/#findComment-852551 Share on other sites More sharing options...
Chris@ETI Posted June 9, 2009 Author Share Posted June 9, 2009 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. Link to comment https://forums.phpfreaks.com/topic/161557-solved-assistance-with-getting-info-out-of-an-array/#findComment-852560 Share on other sites More sharing options...
gevans Posted June 9, 2009 Share Posted June 9, 2009 Your passing two object to an array ($var) These objects are initiated somewhere; $whatever = new your-class(); then, you'll have a class; class your-class { properties and methods in here } I'm looking for that class Link to comment https://forums.phpfreaks.com/topic/161557-solved-assistance-with-getting-info-out-of-an-array/#findComment-852578 Share on other sites More sharing options...
Chris@ETI Posted June 9, 2009 Author Share Posted June 9, 2009 I was able to get the fullname out by doing the following: $vartest = $var[5]->fullname; Thanks for the assistance. Link to comment https://forums.phpfreaks.com/topic/161557-solved-assistance-with-getting-info-out-of-an-array/#findComment-852579 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.