CodeIgniter Forums
array helper, element function - returns false on empty - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: array helper, element function - returns false on empty (/showthread.php?tid=3029)



array helper, element function - returns false on empty - El Forum - 09-05-2007

[eluser]Unknown[/eluser]
Hi all,

This isn't necessarily a "bug", but rather something I think is being done incorrectly.

In the array_helper.php file, the function element(...) returns FALSE on two conditions:
1. The array element is not set.
2. The array element is set but is empty.

I think #2 should be returned as '' (empty) rather than as FALSE. The reason is that sometimes, an array element is purposely set to be empty, like:
Code:
$name['first'] = 'John';
$name['middle'] = '';
$name['last'] = 'Doe';

So we purposely set middle to be '' and not FALSE. By returning FALSE, we are not describing the array element accurately!

Therefore, my proposed fix is simply:
- On line 44 of array_helper.php, change:
Code:
if ( ! isset($array[$item]) OR $array[$item] == "")
to:
Code:
if ( ! isset($array[$item]))


Michael Huynh