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.

977 questions
25
votes
2 answers

Check if array value isset and is null

How to check if array variable $a = array('a'=>1, 'c'=>null); is set and is null. function check($array, $key) { if (isset($array[$key])) { if (is_null($array[$key])) { echo $key . ' is null'; } echo $key . '…
Bartek Kosa
  • 802
  • 1
  • 12
  • 25
23
votes
6 answers

Is empty() enough or use isset()?

Note - I know pretty much about empty() and isset(), what I am asking is the most proper/efficient way of using them. I've just saw at php.net this sentence under empty() reference: No warning is generated if the variable does not exist. That…
Forien
  • 2,644
  • 2
  • 10
  • 26
23
votes
7 answers

How to tell whether a variable has been initialized in C#?

I know this is a dumb question and I guess it must have been asked before. However I am unable to find an answer to my question. Here is some sample code (which of course does not compile) to outline my problem: class test { int[] val1; …
niklasfi
  • 12,699
  • 7
  • 35
  • 51
22
votes
3 answers

Why is array_key_exists 1000x slower than isset on referenced arrays?

I have found that array_key_exists is over 1000x slower than isset at check if a key is set in an array reference. Does anyone that has an understanding of how PHP is implemented explain why this is true? EDIT: I've added another case that seems to…
Kendall Hopkins
  • 39,091
  • 16
  • 60
  • 85
21
votes
7 answers

PHP check if False or Null

I also get confused how to check if a variable is false/null when returned from a function. When to use empty() and when to use isset() to check the condition ?
Harsha M V
  • 50,335
  • 109
  • 326
  • 496
18
votes
3 answers

Isset expression error

I have basically coded a code which populates a list of categories from my database then you are able to select which to delete. I have the issue with the delete code which does not seem to work due to the error: Fatal error: Cannot use isset() on…
user3411002
  • 693
  • 3
  • 9
  • 24
16
votes
1 answer

in php, why empty("0") returns true?

According to php documentation, the following expressions return true when calling empty($var) "" (an empty string) 0 (0 as an integer) 0.0 (0 as a float) "0" (0 as a string) NULL FALSE array() (an empty array) $var; (a variable declared, but…
user2961204
  • 367
  • 1
  • 4
  • 10
16
votes
2 answers

Will isset() return false if I assign NULL to a variable?

I mean... I "set" it to NULL. So isset($somethingNULL) == true?
openfrog
  • 37,829
  • 61
  • 213
  • 364
16
votes
7 answers

Check if variable is_undefined in PHP

In PHP, I want to check if a variable has not been set/defined, where setting a variable NULL is considered set/defined. I'm aware everything here: http://php.net/manual/en/types.comparisons.php including isset(), empty(), and is_null(). None of…
tjbourke
  • 231
  • 1
  • 2
  • 8
15
votes
2 answers

Check if a property exists on magically set properties

There is a lot of SO questions about the subject, notably this one, but it does not help me. There is an ambiguity between property_exists and isset so before asking my question, I'm going to pointing it out: property_exists property_exists checks…
Alain Tiemblo
  • 32,952
  • 14
  • 114
  • 147
14
votes
6 answers

Delete multiple rows by selecting checkboxes using PHP

I want to delete multiple rows from MYSQL database. I have created this delete.php file to select various links and delete them using checkboxes. Links Page

Choose and delete selected…

spyder
  • 310
  • 3
  • 6
  • 16
13
votes
8 answers

PHP Shorthand for isset form POST value

I am creating a form and am just looking for more efficient ways to do things. What I have so far is:

So some of them will…
Drew
  • 6,206
  • 15
  • 58
  • 93
13
votes
2 answers

PHP object isset and/or empty

Is there a way to check if an object has any fields? For example, I have a soap server I am querying using a soap client and if I call a get method, I am either returned an object containing fields defining the soap query I have made otherwise I am…
Chris
  • 11,100
  • 13
  • 44
  • 67
13
votes
6 answers

Why do I need the isset() function in php?

I am trying to understand the difference between this: if (isset($_POST['Submit'])) { //do something } and if ($_POST['Submit']) { //do something } It seems to me that if the $_POST['Submit'] variable is true, then it is set. Why would I…
zeckdude
  • 14,313
  • 39
  • 126
  • 173
13
votes
4 answers

How to check if php://input is set?

I need to check if php://input exists/isset. Does it work with php isset() ? What is the proper way to check it?
sagits
  • 5,030
  • 36
  • 42
1
2
3
65 66