W3docs

PHP check if url parameter exists

To check if a URL parameter exists in PHP, you can use the isset function.

To check if a URL parameter exists in PHP, you can use the isset function. This function returns a boolean value indicating whether a variable with the specified name has been set and is not NULL.

For example, if you want to check if a URL parameter called id exists, you can use the following code:

How to check if a URL parameter exists in PHP?

<?php

if (isset($_GET['id'])) {
  // URL parameter exists
  echo 'URL parameter exists';
} else {
  // URL parameter does not exist
  echo 'URL parameter does not exist';
}

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

You can also use the array_key_exists function to check if a key exists in an array. This function can be used to check if a URL parameter exists in the $_GET array:

Example of checking if a URL parameter exists in PHP by using array_key_exists() function?

<?php

if (array_key_exists('id', $_GET)) {
  // URL parameter exists
  echo 'URL parameter exists';
} else {
  // URL parameter does not exist
  echo 'URL parameter does not exist';
}