Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #15799
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Looking for NULL in arrays |
| Date | 2015-10-27 22:23 +0100 |
| Organization | PointedEars Software (PES) |
| Message-ID | <5273400.d3j8xVGaf9@PointedEars.de> (permalink) |
| References | <d94ctvFn9f4U1@mid.individual.net> <n0mqaa$pnk$3@dont-email.me> |
Denis McMahon wrote:
> On Sun, 25 Oct 2015 16:05:19 +0000, Derek Turner wrote:
>> that will detect a NULL value and stop.
^^^^^^^^^^
> Works with the test cases shown, but otherwise untested so no guarantees
> of any specific behaviour if you feed it garbage.
>
> <?php
>
> $a = array(
> array("fred","jim","peter","susan","mary",0),
> array("fred","jim","susan","mary",0),
> array("fred","susan","mary",0),
> array("fred","mary",0),
> array("fred",0),
> array("fred","jim","susan","mary",0,0),
> array("fred","susan","mary",0,0,0),
> array("fred","mary",0,0,0,0),
> array("fred",0,0,0,0,0)
> );
Flawed testcase: There is not a single occurrence of “null” or “NULL” there.
> foreach ($a as $arr) {
> $idx = 0;
> while ($idx < count($arr)-1 && $arr[$idx] != NULL) $idx += 1;
“!= null” is a comparison recommended against as it does type juggling.
In PHP, “null” (or “NULL”) is a special value. It is *that value* that were
to be detected. And the requirement was to do this *without* “having to use
an 'if' or similar test”, which your approach obviously does not meet. (The
reason for that is that it cannot be met.)
--
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
Looking for NULL in arrays Derek Turner <frderek@suremail.je> - 2015-10-25 16:05 +0000
Re: Looking for NULL in arrays Derek Turner <frderek@suremail.je> - 2015-10-25 16:11 +0000
Re: Looking for NULL in arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-25 19:07 +0100
Re: Looking for NULL in arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-25 19:06 +0100
Re: Looking for NULL in arrays Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2015-10-25 21:01 +0100
Re: Looking for NULL in arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-25 21:58 +0100
Re: Looking for NULL in arrays Jerry Stuckle <jstucklex@attglobal.net> - 2015-10-25 16:33 -0400
Re: Looking for NULL in arrays Derek Turner <frderek@suremail.je> - 2015-10-26 09:42 +0000
Re: Looking for NULL in arrays Jerry Stuckle <jstucklex@attglobal.net> - 2015-10-26 09:45 -0400
Re: Looking for NULL in arrays Derek Turner <frderek@suremail.je> - 2015-10-26 13:57 +0000
Re: Looking for NULL in arrays Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-10-26 17:41 +0100
Re: Looking for NULL in arrays Jerry Stuckle <jstucklex@attglobal.net> - 2015-10-26 12:49 -0400
Re: Looking for NULL in arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-26 22:25 +0100
Re: Looking for NULL in arrays Denis McMahon <denismfmcmahon@gmail.com> - 2015-10-27 03:16 +0000
Re: Looking for NULL in arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-27 22:23 +0100
csiph-web