title: post loop values in a variable (functions.php)
body: <p>So, I have the following post loop to show posts (wp functions.php).</p>
  
  <pre><code>global $post;    
  $args = array( 
      'post_type' =&gt; 'post',      
      'posts_per_page' =&gt; 3,  
      'orderby' =&gt; 'date',            
      'order' =&gt; 'DESC'
      );
  $loop = new WP_Query( $args );
  $id = get_the_ID();
  while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); 
  
  $my_post['sample_id'] =  get_the_title( $id );  
  
  endwhile; 
  wp_reset_postdata();    
  </code></pre>
  
  <p>I need to have the title of posts in an array of values (for example array[title1, title2, title3]).</p>
  
  <p>However, it only picks up one title.</p>
  
  <p>How do I make it so that the <code>$my_post</code> variable can have three values?</p>
  
  <p><strong>(In other words, I simply want to have three titles as a result in a variable)</strong></p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>....
  while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post();   
  array_push($titleArray, get_the_title($id));    
  endwhile;
  $tag_post['sample_id'] =  $titleArray;  
  echo json_encode($tag_post);
  wp_reset_postdata();
  exit;   
  </code></pre>