Re: 1 last error to fix before the application is done!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Yeti wrote:
You might also want to try array_key_exists

if (array_key_exists('loggedin', $_SESSION['userInfo'])) {
// do something with $_SESSION['userInfo']['loggedin']
}

You'd first need to check that the key 'userInfo' existed in the $_SESSION array too.

Personally, I very rarely see the point in using array_key_exists... It's a function call and has overhead where as isset() and empty() are language constructs and (I would hope) are much more efficient (although I've not done any benchmarks).

There are cases where you may want to use array_key_exists where isset() and empty() would fail, e.g.

$arr['foo'] = null;

isset($arr['foo']) == false
!empty($arr['foo']) == false
array_key_exists('foo', $arr) == true

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux