title: PHP Function Help: Creating a Simple Function for Repetitive Task
body: <p>I'm new to utilizing PHP fully, so I think this is just my lack of understanding the proper syntax.</p>
  
  <p>I've got a home page that's being built with WordPress and Advanced Custom Fields. The images are the same thing over and over again for different data, so proper time to create a function correct?</p>
  
  <p>This is my function:</p>
  
  <pre><code>&lt;?php
      function homeMobImgLayout($flexibleLayout) {
          $pageID = '333';
  
          // check if the flexible content field has rows of data
          if( have_rows('$flexibleLayout', $pageID ) ):
  
           // loop through the rows of data
          while ( have_rows('$flexibleLayout', $pageID ) ) : the_row();
  
  
          // 100% Image
          if( get_row_layout() == 'image_100' ):
  
          $img = get_sub_field('img');
          $alt = get_sub_field('alt');
  
          echo '&lt;div class="imagePod width100 clearfix"&gt;';
          echo '&lt;img src="' . $img . '" alt="' . $alt . '" /&gt;';
          echo '&lt;/div&gt;';
  
  
          // 50% Image
          elseif( get_row_layout() == 'image_50' ):
  
          $img = get_sub_field('img');
          $alt = get_sub_field('alt');
  
          echo '&lt;div class="imagePod width50 clearfix"&gt;';
          echo '&lt;img src="' . $img . '" alt="' . $alt . '" /&gt;';
          echo '&lt;/div&gt;';
  
          endif;
  
          endwhile;
  
          else :
          // no layouts found
          endif;
          }
  ?&gt;
  </code></pre>
  
  <p>The only thing that needs to change with each instance of the function call is the two places where I've got the variable $flexibleLayout </p>
  
  <pre><code>(if( have_rows('$flexibleLayout', $pageID ) ):
  
  while ( have_rows('$flexibleLayout', $pageID ) ) : the_row();
  </code></pre>
  
  <p>So then with each instance I call the function, I though I just passed what I wanted this value to be.</p>
  
  <p>Examples:</p>
  
  <pre><code>&lt;?php
      homeMobImgLayout("pet_boarding_imgs");
  ?&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;?php
      homeMobImgLayout("dog_boarding_imgs");
  ?&gt;
  </code></pre>
  
  <p>Where is my understanding and/or syntax incorrect?</p>