Jump to content

removing stdclassobject from array


adam291086

Recommended Posts

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

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

 

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;

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

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.