Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #15781

Re: Looking for NULL in arrays

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 <PointedEars@web.de>
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> (permalink)
References <d94ctvFn9f4U1@mid.individual.net>
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 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

Show key headers only | View raw


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.

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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