Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #15799
| Path | csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.php |
| Subject | Re: Looking for NULL in arrays |
| Date | Tue, 27 Oct 2015 22:23:23 +0100 |
| Organization | PointedEars Software (PES) |
| Lines | 40 |
| Message-ID | <5273400.d3j8xVGaf9@PointedEars.de> (permalink) |
| References | <d94ctvFn9f4U1@mid.individual.net> <n0mqaa$pnk$3@dont-email.me> |
| Reply-To | Thomas 'PointedEars' Lahn <php@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1445981004 13947 eJwFwYEBwCAIA7CXqFCUc1iV/09YQk+kdiQzOBwDmi7vFygyz2BNQDZdTw3ts6JG/qVu2/0BEaARTg== (27 Oct 2015 21:23:24 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Tue, 27 Oct 2015 21:23:24 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| X-User-ID | eJwNyskRwDAIBLCWYNjlKAdj038Jid6iufoEnA4u1zSqJ/VeU4BV+ygYASM1E5tqm90mhTp7wlNf/TtOUXY+K+4Uww== |
| Cancel-Lock | sha1:VtyrJml0b/J/O3vdETD4rnW1fec= |
| X-NNTP-Posting-Host | eJwFwYEBwDAEBMCVKP9hnAr2HyF3MCrvcYKOxRpyIeEazTjs+ce/olnoojJVyK7hiNy87AcH3RC2 |
| Xref | csiph.com comp.lang.php:15799 |
Show key headers only | View raw
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