0

Is it possible to check if an array offset exists or not ?

for example

$url = $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];

it returns

http://localhost/mediabox/home/box/12

when my header is clicked and I am on home page and returns

http://localhost/mediabox/home/box/12/en

when header is clicked and I am on some other page

How can I check if the url array contains that offset or not ?

Thanks

1
  • Could you give an example of what you mean by "if the url array contains that offset"? Commented Mar 23, 2012 at 9:53

3 Answers 3

1

You can use isset(), although I'm not sure I understand your question.

Sign up to request clarification or add additional context in comments.

Comments

0

If under "offset" you mean "key", then use array_key_exists

If you want to find a sbustring, use:

strpos($_SERVER["REQUEST_URI"], "/en") !== false;

Comments

0

you can use function explode ( string $delimiter , string $string [, int $limit ] ) , as delimiter use '/', and then check if end(array)=='en', or check if in_array('en',array), if it may be not at the end of the address

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.