title: PHP: Can I put an if statement inside a variable?
body: <p>I'm still somewhat a beginner to PHP, so sorry if this is a dumb question =)</p>
  
  <p>What I'm trying to do is in a WordPress blog, insert a custom field with multiple values ("ingredients") into my RSS feed. (I also have other posts which are not recipes, which is why the headings "Ingredients" and "Instructions" are inside the if statement.) Here is my entire code so far: </p>
  
  <pre><code>    &lt;?php
      function insertIngredients($content) {
       /* get ingredients into variable $recipeStuff */
       $recipeStuff = 
     if ($ingredients = get_post_custom_values('ingredients')) {
      echo '&lt;h3&gt;Ingredients&lt;/h3&gt;&lt;ul id="ingredients"&gt;';
      foreach ( $ingredients as $key =&gt; $value ) {
     echo '&lt;li&gt;';
     echo $value;
     echo '&lt;/li&gt;';
      } 
      echo '&lt;/ul&gt;&lt;h3&gt;Instructions&lt;/h3&gt;';
     }
       /* add before content */
          $content = $recipeStuff . $content;
          return $content;
      }
      /* Do it! */
      add_filter('the_excerpt_rss', 'insertIngredients');
      add_filter('the_content_rss', 'insertIngredients');
      ?&gt;
  </code></pre>
  
  <p>But a get an "unexpected IF" error, so I guess I can't put all that inside the $recipeStuff variable =) I just can't think of how else to put it in there.</p>
  
  <p>(If it matters, the IF statement is exactly what I use in the posts on the page itself, and it works perfectly!)</p>
  
  <p>Thanks very much in advance for any help! =D</p>
  
  <p><strong>UPDATE!</strong></p>
  
  <p>Here's what I have in my code now:</p>
  
  <pre><code>function insertIngredients($content) {
  /* test for presence of ingredients &amp; set variables */
  if ($ingredients = get_post_custom_values('ingredients')) {
      $heading1 = '&lt;h3&gt;Ingredients&lt;/h3&gt;&lt;ul id="ingredients"&gt;';
      foreach ( $ingredients as $key =&gt; $value ) {
          $ings = '&lt;li&gt;' . $value . '&lt;/li&gt;';
      }
      $heading2 = '&lt;/ul&gt;&lt;h3&gt;Instructions&lt;/h3&gt;';
  }
  /* if no ingredients, variables are empty */
  else { $heading1=''; $ings=''; $heading2=''; }
  
  $recipeStuff = $heading1 . $ings . $heading2 ;
  
  /* add before content */
      $content = $recipeStuff . $content;
      return $content;
  }
  /* Do it! */
  add_filter('the_excerpt_rss', 'insertIngredients');
  add_filter('the_content_rss', 'insertIngredients');
  </code></pre>
  
  <p>I no longer get an error message, but the ingredients are not showing up in the rss feed. I'm not sure if it's because something is still wrong with the code, or if it takes a while to have an effect (though I don't know why that would be the case)? I use FeedBurner, if that makes a difference.</p>
  
  <p>Thanks very much for your answers, everyone. I'm going to try a few different things and update again in a bit. Thanks! =)</p>