title: Store last folder name in path to a variable in PHP
body: <p>I have a php script call "functions.php" that is executed both by itself and by other scripts placed in other folders. I therefore encounter a problem with the code where it tries to include the database file. At first I came up with a quick lazy work around. I amde the script ask twice for the same file like this:</p>
  
  <pre><code>include('../database_file.php');
  include('../../database_file.php'); 
  </code></pre>
  
  <p>However, this is not a good solution. It makes a warning every time, since it can't load one of the files. I have therefore decided to make a Switch Statement that reads if the functions.php file was called by itself or from somewhere else and then include the file from the correct path. (If there is a better workaround, please tell.)</p>
  
  <p>I use the following code to read the current path, so I can make an IF Statement that decides wherefrom my database file should be loaded.</p>
  
  <pre><code>realpath(dirname(__FILE__));
  </code></pre>
  
  <p>This return a path similar to this:</p>
  
  <p>/var/www/website/public</p>
  
  <p>How can I store only the last folder in the path to a variable / Remove everything before the last /?</p>