title: Fatal error: Uncaught TypeError: Cannot access offset of type string on string
body: <p>I am trying to create a website and making use of the YouTube API to display the most recent two uploads from my YouTube Channel. The videos are displaying correctly but the following error is displayed below them.</p>
  <pre><code>Fatal error: Uncaught TypeError: Cannot access offset of type string on string in D:\xampp\htdocs\ImperialSoundsWebsite\index.php:95 Stack trace: #0 {main} thrown in D:\xampp\htdocs\ImperialSoundsWebsite\index.php on line 95
  </code></pre>
  <p>Line 95 code is:</p>
  <pre><code>echo '&lt;iframe width=&quot;1280&quot; height=&quot;720&quot; src=&quot;https://www.youtube.com/embed/' . $video['v_id'] .'&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;';
  </code></pre>
  <p>The full set of code:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;title&gt;Home&lt;/title&gt;
  &lt;html&gt;
  &lt;header&gt;
      &lt;meta charset=&quot;utf-8&quot; /&gt;
  
      &lt;!--Link to style sheet--&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;stylesheet.css&quot;&gt;
      &lt;link href=&quot;https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt;
  
  
      &lt;div class=&quot;box-area&quot;&gt;
          &lt;div class=&quot;wrapper&quot;&gt;
              &lt;div class=&quot;logo&quot;&gt;
                  &lt;a href=&quot;#&quot;&gt;Imperial Sounds&lt;/a&gt;
              &lt;/div&gt;
              &lt;nav&gt;
                  &lt;a href=&quot;index.php&quot;&gt;Home&lt;/a&gt;
                  &lt;a href=&quot;genres.php&quot;&gt;Genres&lt;/a&gt;
                  &lt;a href=&quot;submityourmusic.php&quot;&gt;Submit Your Music!&lt;/a&gt;
                  &lt;a href=&quot;about.php&quot;&gt;About Us/Contact&lt;/a&gt;
              &lt;/nav&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/header&gt;
  &lt;body&gt;
     
      &lt;div class=&quot;banner-area&quot;&gt;
          &lt;h2&gt;Imperial Sounds Music&lt;/h2&gt;
          &lt;h3 style=&quot;color: white; font-family: poppins;&quot;&gt;Home for the latest and best copyright free music!&lt;/h3&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;wrapper&quot;&gt;
          &lt;div class=&quot;our-story&quot;&gt;
              &lt;h2&gt;Our Story&lt;/h2&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;content-area&quot;&gt;
          &lt;div class=&quot;content-img&quot;&gt;
              &lt;img src=&quot;images/logos/youtubeicon.jpg&quot; alt=&quot;icon&quot; /&gt;
          &lt;/div&gt;
          &lt;div class=&quot;wrapper&quot;&gt;
              &lt;p style=&quot;color: black; font-family: poppins; font-size: 28px; font-weight: bold;&quot;&gt;Our Story&lt;/p&gt;
              &lt;p style=&quot;color: black; font-family: poppins; font-size: 20px; display:inline&quot;&gt;Imperial Sounds is a Digital Copyright Free Music Promotor. We share a wide range of different genres of music to suit many different needs for music producers and content creators.&lt;/p&gt;
          &lt;/div&gt;
  
          &lt;div id=&quot;channel-data&quot; class=&quot;col s6&quot;&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;row&quot; id=&quot;video-container&quot;&gt;
  
              &lt;?php
  
              $API_Url = 'https://www.googleapis.com/youtube/v3/';
              $API_Key = 'AIzaSyCZZHuMnTS8q2hXs_-aeEl_lEJcNOX3mlg';
  
              $channelId = 'UCk7cEDiU2CzRAgEmTUciK1A';
  
              $parameter = [
                  'id'=&gt; $channelId,
                  'part'=&gt; 'contentDetails',
                  'key'=&gt; $API_Key
              ];
              $channel_URL = $API_Url . 'channels?' . http_build_query($parameter);
              $json_details = json_decode(file_get_contents($channel_URL), true);
  
              $playlist = $json_details['items'][0]['contentDetails']['relatedPlaylists']['uploads'];
  
              $parameter = [
                  'part'=&gt; 'snippet',
                  'playlistId' =&gt; $playlist,
                  'maxResults' =&gt; '2',
                  'key'=&gt; $API_Key
              ];
              $channel_URL = $API_Url . 'playlistItems?' . http_build_query($parameter);
              $json_details = json_decode(file_get_contents($channel_URL), true);
  
              $my_videos = [];
              foreach($json_details['items'] as $video){
                  //$my_videos[] = $video['snippet']['resourceId']['videoId'];
                  $my_videos[] = array( 'v_id'=&gt;$video['snippet']['resourceId']['videoId'], 
                      'v_name'=&gt;$video['snippet']['title'] );
              }
  
              while(isset($json_details['nextPageToken'])){
                  $nxt_page_URL = $channel_URL . '&amp;pageToken=' . $json_details['nextPageToken'];
                  $json_details = json_decode(file_get_contents($nxt_page_URL), true);
                  foreach($json_details['items'] as $video)
                      $my_videos[] = $video['snippet']['resourceId']['videoId'];
              }
  
              //print_r($my_videos);
              foreach($my_videos as $video){   
                      echo '&lt;iframe width=&quot;1280&quot; height=&quot;720&quot; src=&quot;https://www.youtube.com/embed/' . $video['v_id'] .'&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;';
                  }
              ?&gt;
  
          &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>