title: PHP echo as condition inside PHP if statement
body: <p>I would like to use a PHP echo as a condition inside a PHP if statement.</p>
  
  <p>The aim is to have the list of blog articles written by John Doe, displayed on his biography page.</p>
  
  <p>It worked when I directly wrote the author's name in the <em>if condition</em>:</p>
  
  <pre><code>&lt;!-- current page: biography page --&gt;
  
  &lt;div id="list_of_articles_by_John_Doe"&gt;
  
      &lt;?php foreach(page('magazine')-&gt;children() as $article): ?&gt;
  
          &lt;?php if($article-&gt;author() == 'John Doe'): ?&gt;
              &lt;p&gt;&lt;?php echo $article-&gt;title() ?&gt;&lt;/p&gt;
          &lt;?php endif ?&gt;
  
      &lt;?php endforeach ?&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>But I would like to automate the process, for each writer's biography page to have their own list of articles.</p>
  
  <p>I tried to have as a condition the author of the current biography page ($page):</p>
  
  <pre><code>&lt;!-- current page: biography page --&gt;
  
  &lt;div id="automatic_list_of_articles"&gt;
  
      &lt;?php foreach(page('magazine')-&gt;children() as $article): ?&gt;
  
          &lt;?php if($article-&gt;author() == $page-&gt;author()): ?&gt;
              &lt;p&gt;&lt;?php echo $article-&gt;title() ?&gt;&lt;/p&gt;
          &lt;?php endif ?&gt;
  
      &lt;?php endforeach ?&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>but it makes another issue: it does not work because inside the <em>foreach statement</em>, <code>$page-&gt;author()</code> (condition in the if statement) does not echo the author once, but one time for each <code>page('magazine')-&gt;children() as $article</code>.</p>
  
  <p>The condition <code>if($article-&gt;author() == $page-&gt;author())</code> does not work in this case, as <code>$page-&gt;author()</code> is not strictly the writer's name.</p>
  
  <p>I'm wondering how to call <code>$page-&gt;author()</code> to echo the writer's name only once, when inside the foreach statement.</p>