Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing an ArrayAccess item directly
    primarykey
    data
    text
    <p>I'm trying to get an item of an array by its key. The array is in fact a SolrObject, which implements ArrayAccess, so I understand that I can access its items as I would in an array.</p> <p>This is the structure of my $myobject:</p> <pre><code>SolrObject Object ( [116809] =&gt; SolrObject Object ( [title] =&gt; Array ( [0] =&gt; First value ) [description] =&gt; Array ( [0] =&gt; Second value ) ) [591978] =&gt; SolrObject Object ( [title] =&gt; Array ( [0] =&gt; Third value ) [description] =&gt; Array ( [0] =&gt; Forth value ) ) ) </code></pre> <p>So, if I try</p> <pre><code>var_dump($myobject[116809]); </code></pre> <p>I get NULL.</p> <p>But if I try</p> <pre><code>echo array_key_exists(116809, $myobject); </code></pre> <p>I get <strong>1</strong></p> <p>If I try to iterate $myobject with a foreach, I can access its elements correctly.</p> <p><strong>Why can't I access directly one element by its key?</strong></p> <p><strong>EDIT:</strong> Answering to @ircmaxell, this is the var_dump:</p> <pre><code>object(SolrObject)#219 (50) { [116809]=&gt; object(SolrObject)#220 (2) { ["title"]=&gt; array(1) { [0]=&gt; string(43) "First value" } ["description"]=&gt; array(1) { [0]=&gt; string(82) "Second value" } } [591978]=&gt; object(SolrObject)#221 (2) { ["title"]=&gt; array(1) { [0]=&gt; string(104) "Third value" } ["description"]=&gt; array(1) { [0]=&gt; string(95) "Fourth value" } } } </code></pre> <p>And this is the result of var_dump($myobject->getPropertyNames());</p> <pre><code>array(2) { [0]=&gt; string(0) "" [1]=&gt; string(0) "" } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload