Q: Making a variable of a variable in wordpress I'm trying to put the ID from code 1 in to code 2. Can anyone help me? The ID is the logged in user ID. I want to re-use this ID in code 2. As you can see code 2 got ID 1 at the moment, but I need to assign the ID given from code 1 in to code 2 in stead of the ID "1"
Code1:
<?php $user_info = get_userdata(1); echo 'User ID: ' . $user_info->ID . "\n"; ?>

Code2:
<?php
$user_id = 1;
$user_blogs = get_blogs_of_user( $user_id );
echo 'User '.$user_id.'\'s blogs:<ul>';
foreach ($user_blogs AS $user_blog) {
    echo '<li>'.$user_blog->blogname.'</li>';
}
echo '</ul>';
?>

The code will be placed in the same file. I'm trying to merge these 2 insted of using ID 1 in code 2

A: You are doing it wrong here. Your code one gives id of the current blog not the user. You need to change your code;
CODE 1: 
$user_id = get_current_user_id(); //get the current logged in user id

CODE 2:     
$user_blogs = get_blogs_of_user( $user_id ); //get the blogs of logged in user
echo 'User '.$user_id.'\'s blogs:<ul>';
   foreach ($user_blogs as $user_blog) {
       echo '<li>'.$user_blog->blogname.'</li>';
   }
echo '</ul>';

Hope this is what you want :)
EDIT :
This is your current code:
CODE 1: 
 <?php 
     $user_info = get_userdata(1); 
     echo 'User ID: ' . $user_info->ID . "\n"; 
  ?> 

CODE 2: 
   <?php $user_id = 1; 
         $user_blogs = get_blogs_of_user( $user_id ); 
         echo 'User '.$user_id.'\'s blogs:<ul>'; 
         foreach ($user_blogs AS $user_blog) { echo '<li>'.$user_blog->blogname.'</li>'; } echo '</ul>'; 
    ?>

Here you are assigning $user_id =1 directly. No need of that. You can do that directly in code 1. 
Just change your current code to this:
CODE 1: 
 <?php 
     $user_id = get_current_user_id(); //get the current logged in user id
     echo 'User ID: ' . $user_id . "\n"; 
 ?> 

CODE 2: 
   <?php 
         $user_blogs = get_blogs_of_user( $user_id ); 
         echo 'User '.$user_id.'\'s blogs:<ul>'; 
         foreach ($user_blogs AS $user_blog) { echo '<li>'.$user_blog->blogname.'</li>'; } echo '</ul>'; 
    ?>

This will work provided your both codes are in same file.
This is what you want
