title: if statement in foreach loop using last true value when false
body: <p>I have an array being looped with an if-else statement in it. The condition is if the name starts with a dot put the string in <code>$gridNames</code> else put the string in <code>$cssNames</code>. Somehow the last name that was valid for <code>$gridNames</code> is being used for the rest of the loop although the condotion being false.</p>
  
  <p>Here's the <code>$selector["name"]</code> array:</p>
  
  <pre><code>string(4) ".row"
  string(10) ".inner_row"
  string(7) ".column"
  string(13) ".inner_column"
  string(12) "hey im a div"
  string(8) "column 1"
  string(5) "row 2"
  </code></pre>
  
  <p>And the code itself: </p>
  
  <pre><code>foreach ($element_css["element_css"] as $selector) {
    $name = $selector["name"];
    $lenght = strlen($name);
    $firstLetter = substr($name, 0, -($lenght - 1));
    if ($firstLetter == ".") {
        $gridName = substr($name, 1, $lenght);
    } else {
        $nameByWords = explode(" ", $name);
        foreach ($nameByWords as $word) {
          $allWords .= $word;
        }
        $cssName = $allWords;
        $allWords = "";
    }
    var_dump($gridName);
  }
  </code></pre>
  
  <p>The <code>var_dump</code> gives me:</p>
  
  <pre><code>string(3) "row"
  string(9) "inner_row"
  string(6) "column"
  string(12) "inner_column"
  string(12) "inner_column"
  string(12) "inner_column"
  string(12) "inner_column"
  </code></pre>
  
  <p>The result I want is:</p>
  
  <pre><code>string(3) "row"
  string(9) "inner_row"
  string(6) "column"
  string(12) "inner_column"
  </code></pre>