title: Why can't I access a variable that's inside an If statement?
body: <p>Here's the IF statement. I want to access the timeStampCleaned variable later on.</p>
  
  <pre><code>    if ($xmlRatesTime = '') {
          $timeStampCleaned = date('j F Y H:i', $ratesTimeStamp); // Convert unix timestamp into date format
      } else {
          // ...
      }
  </code></pre>
  
  <p>Like so:</p>
  
  <pre><code>    if(empty($ratesTimeStamp)) {
  
          $newXML = simplexml_load_file('cache/rates.xml');
  
          $child = $newXML-&gt;addChild('currency');
          $child-&gt;addAttribute('id', ''.$to.'');
          $child-&gt;addChild('title', $toTitle);
          $child-&gt;addChild('loc', $toLocation);
          $child-&gt;addChild('rate', $finalRate);
          $child-&gt;addChild('timestamp', $timeStamp);
  
          $dom = new DOMDocument('1.0');
          $dom-&gt;preserveWhiteSpace = false;
          $dom-&gt;formatOutput = true;
          $dom-&gt;loadXML($newXML-&gt;asXML());
          $newXMLdomCleaned = $dom-&gt;saveXML();
  
          file_put_contents('cache/rates.xml', $newXMLdomCleaned);
      }
  </code></pre>
  
  <p>But I'm getting the error:</p>
  
  <pre><code>Notice: Undefined variable: timeStampCleaned in ...file... on line 208
  </code></pre>
  
  <p>From what I understand, accessing variables within if statements is fine. So I have no idea why this isn't working!?</p>
  
  <p>Thanks</p>