Skip to content

Instantly share code, notes, and snippets.

@alixaxel
Last active December 12, 2015 08:09
Show Gist options
  • Save alixaxel/4742340 to your computer and use it in GitHub Desktop.
Save alixaxel/4742340 to your computer and use it in GitHub Desktop.
<?php
public static function Segment($key = null, $default = false)
{
static $result = null;
if (is_null($result) === true)
{
if (count($result = explode('/', substr(self::Value($_SERVER, 'PHP_SELF'), strlen(self::Value($_SERVER, 'SCRIPT_NAME'))))) > 0)
{
$result = array_values(array_filter($result, 'strlen'));
}
}
if (isset($key) === true)
{
if (is_int($key) === true)
{
return self::Value($result, $key, $default);
}
else if (($key = array_search($key, $result)) !== false)
{
return self::Value($result, $key + 1, $default);
}
return false;
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment