By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,367 Members | 946 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,367 IT Pros & Developers. It's quick & easy.

Errors from a NULL value

P: n/a
I have the following function which works great except when I
encounter a NULL value in my array ($aidlook) and then I get "wrong
data type" errors. I thought about doing a NULL check and creating a
value but didn't know if there was a more effective method. TIA

***************************
if (!in_array($userid, $aidlook))
{
if ($qstatus === 1)
{
}
echo "<a href='apage.php?qid=$qid'>THIS LINK</a>";
} else {
echo "NEGATIVE.</a>";

}

*******************************8

May 20 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Akhenaten wrote:
I have the following function which works great except when I
encounter a NULL value in my array ($aidlook) and then I get "wrong
data type" errors. I thought about doing a NULL check and creating a
value but didn't know if there was a more effective method. TIA
Works for me:

<?php
$foo = array('moon' ='stars', 'test' =null);
var_dump(in_array('stars', $foo)); // true
var_dump(in_array(null, $foo)); // true
var_dump(in_array('not-in-array', $foo)); // true
?>

However, if you try:

<?php
in_array('foo', null);
?>

You will get your wrong datatype error. In that case, you should check
if $aidlook itself is null (or a non-array), like such:

<?php
if (!is_array($aidlook)) $aidlook = array($aidlook);
?>

- --
Edward Z. Yang GnuPG: 0x869C48DA
HTML Purifier <htmlpurifier.org Anti-XSS HTML Filter
[[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGT8D8qTO+fYacSNoRAl7ZAKCDBEpXOb82sULygtRkkt nWxWlzdACbBbFL
uN78h8IQ7jAdo0BOoc9eqVg=
=jj9v
-----END PGP SIGNATURE-----
May 20 '07 #2

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Edward Z. Yang wrote:
var_dump(in_array('not-in-array', $foo)); // true
Quick amendment: the result of this function is actually false, as is
implied by the needle string.

- --
Edward Z. Yang GnuPG: 0x869C48DA
HTML Purifier <htmlpurifier.org Anti-XSS HTML Filter
[[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGT8EnqTO+fYacSNoRAp6HAJ9aUeP4Wp1Lbp0DBtPc0u DoXgnxVQCaAhnj
omDoHYBc4BbeOMFyAskuvck=
=YB/A
-----END PGP SIGNATURE-----
May 20 '07 #3

P: n/a
Thx Edward,

<?php
if (!is_array($aidlook)) $aidlook = array($aidlook);
?>

That fixed me up perfectly when my didn't return.
May 20 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.