title: Make object array in php
body: <p>i used to do object arrays in javascript or java but i feel like it doesn't work in php.</p>
  <p>In JS i will do roughly :</p>
  <pre class="lang-js prettyprint-override"><code>    var users = [];
      var user_password = [{
          user : &quot;username1&quot;,
          pass : &quot;password&quot;
      }, {
          user : &quot;username2&quot;,
          pass : &quot;password&quot;
      }, {
          user : &quot;username3&quot;,
          pass : &quot;password&quot;
      }]
      
      user_password.forEach(anUser =&gt; {
          var user = {
              username: anUser.user,
              password: anUser.pass
          }
          users.push(user);
      });    
      
      return users;
      
      // return : [{
      //     username : &quot;username1&quot;,
      //     password : &quot;password&quot;
      // }, {
      //     username : &quot;username2&quot;,
      //     password : &quot;password&quot;
      // }, {
      //     username : &quot;username3&quot;,
      //     password : &quot;password&quot;
      // }]
  </code></pre>
  <p>But when i make this in PHP :</p>
  <pre class="lang-php prettyprint-override"><code>    $yourls_user_passwords = [
        'projet@gmail.com' =&gt; 'phpass:!2a!08!dJOIkAq/TJZIpwYHcqwf4uDwcraOJDIGIDSOJGOIDSJGOIJSDOIGJ.og2' /* Password encrypted by YOURLS */ ,
          'username6@gmail.com' =&gt; 'phpass:!2a!08!9Fqoufb2b70Oq6xsRfCKu.q7vxxMdSLxWXVbZV2C1EBAJcAPn2Ldy' /* Password encrypted by YOURLS */ ,
          'username@gmail.com' =&gt; 'phpass:!2a!08!DJpKEAhWtrrPrQqi9uOSreUM1ZROFsQUr5fYiq7ADwa/3EehxjgKO' /* Password encrypted by YOURLS */ ,
          // You can have one or more 'login'=&gt;'password' lines
      ];
      
      // roles of different users
      $amp_role_assignment = array(
          'administrator' =&gt; array(
              'projet@gmail.com',
              // add other administrator
          ),
          'editor' =&gt; array(
              // add other editor
          ),
          'contributor' =&gt; array(
              'username6@gmail.com',
              'username@gmail.com',
              // add other contributor
          ),
      );
  
      $users = array();
  
      foreach ($yourls_user_passwords as $username =&gt; $password) {
          $anUser = (object)[];
          foreach ($amp_role_assignment as $role =&gt; $users) {
              foreach ($users as $user){
                  if ($user == $username) {
                      $anUser-&gt;username = $username;
                      $anUser-&gt;role = $role;
                  }
              }
          }
          var_dump(&quot;&lt;/br&gt;USER OBJECT&lt;/br&gt;&quot;);
          var_dump($anUser);
          $users[] = $anUser;
      }
      var_dump(&quot;&lt;/br&gt;&lt;/br&gt;USERS ELEMENT 1&lt;/br&gt;&quot;);
      var_dump($users[0]);
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/D2yw6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D2yw6.png" alt="var_dump" /></a></p>
  <p>When I display the elements one by one before adding them to my user array it does display each object one by one to me but when I display them directly with their index it doesn't work.</p>
  <p>I don't understand, is there something wrong with my code? Thank you very much by advance !</p>