Shoaib Shoaib - 3 months ago 22
PHP Question

Get the single element from the array

I got follows array after print the whole array from db how i can get a single element like e_domains from this printed array:

stdClass Object
[id] => 1
[uni_origin] => Aachen
[e_domains] =>

I have print this array like this:

if ($results ) {
foreach ( $results as $result ){
echo'<pre>'; print_r($result) ;
//echo $result->('e_domains');

Answer Source

First off, that's not an array, that's an object. Like it says: "stdClass Object".

Access object properties like this:


In your case, it would be:


There are much more to learn on the subject, like static properties, visibility etc. In your case, the above example will work.

Read more about classes and objects in the manual: