Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.php Subject: Re: Looking for NULL in arrays Date: Sun, 25 Oct 2015 19:06:32 +0100 Organization: PointedEars Software (PES) Lines: 46 Message-ID: <1854724.EiBtr6myrt@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1445796394 26109 eJwNxsEBwCAIA8CVREmAcQRk/xHaex0OhWVKUDGYCjdS0tCQSu0Vfo8/6TRfMX+3wd7eSfcrHxDdEIs= (25 Oct 2015 18:06:34 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Sun, 25 Oct 2015 18:06:34 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwNwoERACEIA7CVigLVcUDt/iP8XxIzLQ89Iz0U6oMCDVWAmalSyE6HuKd46W+ac2P3eX1L/N03fEmDXB9PfRW+ Cancel-Lock: sha1:okBHpJNqrkUbV4yfCzF9m5vz2iw= X-NNTP-Posting-Host: eJwVysERwCAMA7CVCMYOHqdHyP4jcNVbhEInl6jFZhfT17Nx6sO+Zu6Rw+XwP8IlDsQE1NoXDwn+D9g= Xref: csiph.com comp.lang.php:15781 Derek Turner wrote: > The problem is not that I don't know how to iterate through an array - > the problem is that there are so many ways and I can't see the wood for > the trees -which is the easiest method? foreach > I have a simple array called $weeks. At the moment it contains either > three string values or 5 could easily make it a consistent five if > necessary. Your sentences are incoherent. You cannot just be posting as you are just thinking; you have to make an effort to put your thoughts in proper words. In doing that, you will learn to think clearly, maybe even arrive at the solution yourself. > $weeks[1] always contains a string. [2], [3] etc. either contain a string > or NULL from mysql query. > > I want to iterate through in key order until either [5] or a NULL value > is found. What would do that, please? “foreach” over an array that contains the array keys in order. RTFM. > Is there a simple way without having to use an 'if' or similar test? No. > I'm thinking something similar to > > while ($row = $result->fetch_asoc()); > > that will detect a NULL value and stop. This will detect a false-value, *including* NULL, and then stop. > IYSWIM. Pardon? -- PointedEars Zend Certified PHP Engineer Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.