PHP variable scope between code blocks
<p>I am new to PHP (still) and keep learning.</p>

<p>I often have to retrieve a certain variable and access its properties.</p>

<pre><code>&lt;?php
      $id = $_REQUEST['id'];
      $user_info = get_userdata($id);

      echo('Username: '        . $user_info-&gt;user_login . "&lt;br&gt;");
      echo('User level: '      . $user_info-&gt;user_level . "&lt;br&gt;");
      echo('User ID: '         . $user_info-&gt;ID . "&lt;br&gt;");
      echo('First Name: '      . $user_info-&gt;user_firstname . "&lt;br&gt;");
      echo('Family Name: '     . $user_info-&gt;user_lastname . "&lt;br&gt;");
      echo('user_registered: ' . $user_info-&gt;user_registered . "&lt;br&gt;");
?&gt;
</code></pre>

<p>I would prefer to once retrieve <code>$user_info = get_userdata($id);</code> and then use it when needed
in the same file but in different <code>&lt;?php?&gt;</code> blocks</p>

<pre><code>&lt;?php
    $id = $_REQUEST['id'];
    $user_info = get_userdata($id);
?&gt;

&lt;some HTML&gt;

&lt;?php echo $user_info-&gt;user_login; ?&gt;

&lt;some HTML&gt;

&lt;?php echo $user_info-&gt;user_login; ?&gt;
</code></pre>

<p>But I suspect <code>$user_info</code> cannot be shared between blocks because it is not global.
What is usual practice for that?</p>
