Questions tagged [isset]

Determine if a variable is set and is not NULL

Description [source: https://php.net/manual/en/function.isset.php]

bool isset (mixed$var [,mixed$... ] )

Determine if a variable is set and is not NULL.

If a variable has been unset with unset(), it will no longer be set. isset() will return FALSE if testing a variable that has been set to NULL. Also note that a NULL byte ("\0") is not equivalent to the PHP NULL constant.

If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are set. Evaluation goes from left to right and stops as soon as an unset variable is encountered.

1015 questions
7
votes
3 answers

PHP associative arrays - how to treat integer as string

I have a simple associative array. $a = array("a"=>"b", "c"=>"d"); I want to check if the key "1" exists in the array, e.g. isset($a["1"]); This string is being treated as an integer, so that echo $a["1"]; //prints "d" How do I get it to treat it…
bcoughlan
  • 25,987
  • 18
  • 90
  • 141
7
votes
1 answer

PHP Performance of !isset() vs === null

I'm aware of the benchmarks for isset() vs empty(), but I have code I need to execute only when the argument is null. This is in a function that executes many times so I'd like to optimize it. I know that isset() is faster than empty(), but what…
Bob Ray
  • 1,105
  • 10
  • 20
7
votes
1 answer

if / elseif `isset` multiple submit inputs doesn't work

I have several submit inputs (buttons) on a page, with the following issetconditions: if ( isset( $_POST[ 'noranTelChecks' ] ) ) { // user requested noranTelCheck sheet header( 'location: noranTelChecks.php' ); } elseif ( isset( $_POST[…
commnux
  • 485
  • 2
  • 9
7
votes
4 answers

How to tell whether a variable in ASP has been declared

Let me start off by saying I'm a PHP developer, not an ASP one. (And I really wish ASP had isset().) And I'm working in a live environment so I don't really have an opportunity to do any testing. All the resources I've found suggest different ways…
WNRosenberg
  • 1,862
  • 5
  • 22
  • 31
7
votes
3 answers

Difference between `if (isset($_SESSION))` and `if ($_SESSION)`?

I've noticed that frequently people simply write while I have been using: Could someone explain the difference when checking if a variable is set (that's…
d-_-b
  • 21,536
  • 40
  • 150
  • 256
6
votes
5 answers

What's better, isset or not?

Is there any speed difference between if (isset($_POST['var'])) or if ($_POST['var']) And which is better or are they the same?
James
  • 5,942
  • 15
  • 48
  • 72
6
votes
3 answers

If isset for constants, but not defined?

If I set a constant to = '', How to I check if constant has something inside ? (ie see if it is set to something other than the empty string.) defined() does not do what I want, because it is already defined (as ''). isset() does not work with…
Cameleon
  • 453
  • 1
  • 6
  • 16
6
votes
8 answers

PHP Make a simple if-isset-empty function

I'm coding a worksheet app for a printer company. I'm getting flood of forms. For every single input field I have to check if the $_POST variables are set, and if, so echo back the value. (In case of some error, for example after a validation…
Kael
  • 565
  • 2
  • 8
  • 18
6
votes
3 answers

REST API not working in addon domain

I am new to php and handling server side. I have a domain "www.example.co.in". And another addon domain "www.example.com". I have created a new folder "www.example.com" at the root folder(public_html) of "www.example.co.in" cpanel…
OnePunchMan
  • 720
  • 15
  • 33
6
votes
2 answers

Test if session is started

How do you test to see if sessions are on. This is not the way... session_start(); if(isset($_SESSION)) { echo "sessions ON
"; } else{ echo "sessions OFF
"; } session_destroy(); if(isset($_SESSION)) { echo "sessions…
TMP file guy
  • 249
  • 2
  • 4
  • 9
6
votes
6 answers

php: write isset function which returns value or null

I have the following code in numerous places (thousands of places) around my project: $foo = isset($mixed) ? $mixed : null; Where $mixed can be anything: array, array element, object, object property, scalar, etc. For example: $foo =…
Leo
  • 265
  • 3
  • 9
6
votes
1 answer

isset and !empty not passing through a check for uploaded files

I have an upload form with a file to be uploaded. The issue I have is that even when no file is uploaded the if(isset($_FILES)) OR if(!empty($_FILES)) still passes as successful: $_FILES = $HTTP_POST_FILES; if($_POST['type'] == 'photo' &&…
kalpaitch
  • 5,193
  • 10
  • 43
  • 67
6
votes
3 answers

Why can't I assign a variable inside of isset? - php

Recently, I've attempted to be tricky and assign a variable inside of an isset function. I tried to do it like so if(isset($accountid =$_POST['Recipient'])) { // my code here ... } However, when I do this I receive the error syntax error,…
Stephen
  • 2,360
  • 2
  • 18
  • 23
6
votes
2 answers

How to check if a multidimensional array item is set in JS?

How to check if a multidimensional array item is set in JS? w[1][2] = new Array; w[1][2][1] = new Array; w[1][2][1][1] = 10; w[1][2][1][2] = 20; w[1][2][1][4] = 30; How to check if w[1][2][1][3] is set? Solution with if (typeof w[1][2][1][3] !=…
Colargol
  • 749
  • 4
  • 14
  • 26
5
votes
8 answers

PHP isset($_SESSION[$var]) Not working at all

In my project, I have a wrapper class for $_SESSION, so session variables can be accessed by $session->var. I was trying to check if session variables were set or not using isset: if (!isset($this->session->idUser)) { ... } but isset is not…
Jormundir
  • 430
  • 4
  • 11