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


Groups > comp.lang.php > #17642

Re: array_filter with two conditions

Path csiph.com!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.php
Subject Re: array_filter with two conditions
Date Fri, 5 Jan 2018 13:29:37 +0100
Organization solani.org
Lines 16
Message-ID <p2nr3h$u2c$1@solani.org> (permalink)
References <fe3760f6-83ed-47b3-8402-880fd3d26408@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace solani.org 1515155377 30796 eJwFwYkBgDAIA8CVeBIo42gs+4/gHbO81CgWuFz4MiDz2OZspmzue7yR0/EZda4Bcj3KEX4DuxBt (5 Jan 2018 12:29:37 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Fri, 5 Jan 2018 12:29:37 +0000 (UTC)
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2
Cancel-Lock sha1:ASro/VmlFVEy7Jn322E8VOkhMwg=
X-NNTP-Posting-Host eJwNxMEBwCAIA8CVpEIC66Bk/xHsPS42DIeOgIdCh8lMdbpd1fQCv9a/DDEqu6ihN7jXaPAAHXQRLQ==
X-User-ID eJwVyMERwDAIA7CVIMQmjFNavP8IueopBJ1vboIbgmi1HpEcFNBL9Gg7vsrG4suYPlbKpP7KCwKRECU=
In-Reply-To <fe3760f6-83ed-47b3-8402-880fd3d26408@googlegroups.com>
Content-Language de-DE
Xref csiph.com comp.lang.php:17642

Show key headers only | View raw


On 05.01.2018 at 01:11, jans wrote:

> I am having trouble debugging this?  I can't get it to print out the value if it is even or the word "odd" if it is odd?   The initial funcitons work but I don't know how to use the array_filter with two conditions?

Why do you want to filter the array for this purpose?  It seems to me
the simplest approach would be to iterate over the array, and then
conditionally printing what is desired.  For instance:

  <?php
  $arr = array(1,2,6,7,9,4,10,11,12,3,13,24);
  foreach ($arr as $val) {
      echo ($val%2 ? "odd" : $val), PHP_EOL;
  }

-- 
Christoph M. Becker

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


Thread

array_filter with two conditions jans <janis.rough@gmail.com> - 2018-01-04 16:11 -0800
  Re: array_filter with two conditions Jerry Stuckle <jstucklex@attglobal.net> - 2018-01-04 20:03 -0500
  Re: array_filter with two conditions Arno Welzel <usenet@arnowelzel.de> - 2018-01-05 02:10 +0100
  Re: array_filter with two conditions "Christoph M. Becker" <cmbecker69@arcor.de> - 2018-01-05 13:29 +0100
    Re: array_filter with two conditions jans <janis.rough@gmail.com> - 2018-01-08 14:29 -0800
  Re: array_filter with two conditions Postiljon Petskin <yyyyyyyyyyyywwwww@zohomail.eu> - 2023-04-22 08:47 -0700

csiph-web