title: accessing collections of cassandra in php
body: <p>here is the table I have created in cassandra database</p>
  
  <pre><code>create table followers(
  username text,
  followedby list&lt;text&gt;,
  primary key(username));
  </code></pre>
  
  <p>using php I have to access the list of followers for a particular username($user="raj"). Below is the query I am using</p>
  
  <pre><code>$result=$session-&gt;execute(new Cassandra\SimpleStatement("select followedby from followers where username='$user'"));
  </code></pre>
  
  <p>I could not figure out how to store the result of the query using php so that all the elements in the list can be accessed one by one i.e. whether to use array or list in php. Below is one of the codes I tried.</p>
  
  <pre><code>foreach($result as $row)
  {
      $ans=$row['followed'];
      echo $ans[0];
      echo $ans[1];
  }
  </code></pre>
  
  <p>but the code gave the following error:</p>
  
  <blockquote>
    <p>Cannot use object of type Cassandra\Collection as array in C:\wamp64\www\LoginRegistrationForm\home.php on line 68</p>
  </blockquote>
  
  <p>What is the correct method so that I can access all the elements in the list one by one?</p>