adam291086 Posted March 13, 2009 Share Posted March 13, 2009 ok i have this array Array ( [0] => stdClass Object ( [idSkills] => 2 [Persons_idUser] => 1 [skillName] => dfdsfdsf [skillLevel] => Good [verified] => 0 [howVerified] => ) [1] => stdClass Object ( [idSkills] => 1 [Persons_idUser] => 1 [skillName] => dfgfgfd [skillLevel] => Basic [verified] => 1 [howVerified] => ) ) how can u make it a associative array? i have tried $data = (array) $data; but that only seems to work if theres only one stdclass object Link to comment https://forums.phpfreaks.com/topic/149241-removing-stdclassobject-from-array/ Share on other sites More sharing options...
adam291086 Posted March 13, 2009 Author Share Posted March 13, 2009 i am trying $test = $db->get_results("SELECT * FROM skills WHERE Persons_idUser='".$_SESSION['idUser']."'"); foreach($test as $t) { echo $t; } but i get the error Catchable fatal error: Object of class stdClass could not be converted to string in /home/adamplo1/public_html/CASE/files/skills.php on line 33 Link to comment https://forums.phpfreaks.com/topic/149241-removing-stdclassobject-from-array/#findComment-783727 Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2009 Share Posted March 13, 2009 If you don't want to use object notation to access the data, why are you using a function that retrieves the data as an array of objects? $t is an object, to access the elements in it you must use object notation - echo $t->idSkills; echo $t->Persons_idUser; Link to comment https://forums.phpfreaks.com/topic/149241-removing-stdclassobject-from-array/#findComment-783731 Share on other sites More sharing options...
adam291086 Posted March 13, 2009 Author Share Posted March 13, 2009 basically i am using the ez_sql.php class and that returns and array with stdclass objects. I just want the array without the stdclass objects. this will work if there is one stdclass object but not if theres two $data = (array) $data; Link to comment https://forums.phpfreaks.com/topic/149241-removing-stdclassobject-from-array/#findComment-783733 Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2009 Share Posted March 13, 2009 The second parameter in the get_result() method specifies how the data is to be returned, the default is OBJECT - function get_results($query=null, $output = OBJECT) The other values (defined constants) are - ARRAY_A for an associative array ARRAY_N for a numerical array Link to comment https://forums.phpfreaks.com/topic/149241-removing-stdclassobject-from-array/#findComment-783747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.