title: Remove duplicates from CSS file
body: <p>Today I tried use SCCS Compiler (<a href="http://leafo.net/scssphp/" rel="nofollow">http://leafo.net/scssphp/</a>) and i fell in love with this tool, but I need one more feature.</p>
  
  <p>I generated compressed CSS file like that:</p>
  
  <pre><code>html,body{height:100%;}html,body{height:100%;}html,body{height:100%;}@media all and (max-width:960px){body{height:80%;width:95%;}}@media all and (max-width:480px){body{height:100%;width:90%;}}nav ul{margin:0;padding:0;list-style:none;}nav li{display:inline-block;}nav a{display:block;padding:6px 12px;text-decoration:none;}html,body{height:100%;}html,body{height:100%;}@media all and (max-width:960px){body{height:80%;width:95%;}}@media all and (max-width:480px){body{height:100%;width:90%;}}html,body{height:100%;}
  </code></pre>
  
  <p>Uncompressed file:</p>
  
  <pre><code>html, body {
    height: 100%;
  }
  html, body {
    height: 100%;
  }
  html, body {
    height: 100%;
  }
  @media all and (max-width: 960px) {
    body {
      height: 80%;
      width: 95%;
    }
  }
  @media all and (max-width: 480px) {
    body {
      height: 100%;
      width: 90%;
    }
  }
  nav ul {
    margin: 0;
    padding: 0;
    list-style: none;
  }
  nav li {
    display: inline-block;
  }
  nav a {
    display: block;
    padding: 6px 12px;
    text-decoration: none;
  }
  html, body {
    height: 100%;
  }
  html, body {
    height: 100%;
  }
  @media all and (max-width: 960px) {
    body {
      height: 80%;
      width: 95%;
    }
  }
  @media all and (max-width: 480px) {
    html, body {
      height: 100%;
    }
    body {
      height: 100%;
      width: 90%;
    }
  }
  html, body {
    height: 100%;
  }
  </code></pre>
  
  <p>I have this code in string variable in PHP and I need remove duplicates. It's sounds easy, array_unique and that's it. Of course. But i need unique code for normal css and for every media separately. So i need output:</p>
  
  <pre><code>html, body {
    height: 100%;
  }
  nav ul {
    margin: 0;
    padding: 0;
    list-style: none;
  }
  nav li {
    display: inline-block;
  }
  nav a {
    display: block;
    padding: 6px 12px;
    text-decoration: none;
  }
  @media all and (max-width: 960px) {
    body {
      height: 80%;
      width: 95%;
    }
  }
  @media all and (max-width: 480px) {
    html, body {
      height: 100%;
    }
    body {
      height: 100%;
      width: 90%;
    }
  }
  </code></pre>
  
  <p>So this script don't remove html,body { height: 100% } from @media all and (max-width: 480px) because in this media is unique.</p>
  
  <p>Could you help me?
  If you can put every media queries at the end of the file I would be happy.</p>