Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42384 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70817 invoked from network); 26 Dec 2008 18:28:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Dec 2008 18:28:32 -0000 Authentication-Results: pb1.pair.com smtp.mail=drwoland@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=drwoland@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.21 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: drwoland@gmail.com X-Host-Fingerprint: 209.85.218.21 mail-bw0-f21.google.com Received: from [209.85.218.21] ([209.85.218.21:49000] helo=mail-bw0-f21.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D7/1B-33750-F4225594 for ; Fri, 26 Dec 2008 13:28:32 -0500 Received: by bwz14 with SMTP id 14so10262466bwz.23 for ; Fri, 26 Dec 2008 10:28:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:cc:in-reply-to:mime-version:content-type:references :x-google-sender-auth; bh=ZR9W7dE6dTD/xSs16L7+UIFpfHpldrEGnB1iC6yXIp4=; b=feYzsdbCbWuPhcJyOjj3h237WZZhLXUk2v2bq2OFftNSJzytTjezIFyUjADZm/gBdk t68QvbFwNWa9565VM+P4PpWQB/XsfLBajR4qiPIllFIKT3AUIxvnADETB36lAfWsDHDt G9hcEZcQKguyYKofHweuo287Unw+Stz5PqXcc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version :content-type:references:x-google-sender-auth; b=U5EXT+MbPkhrahc85bzJPfEEYSYz9avcEznwmS8igUWaDJLlBlMApc4Kb28agYXJK6 srwDZqz2ECYgrtawQ/vgzjV1PK/eoVQOTkIh0mhqNHGlW43E3kF5NpJIoDEtU1ZTPp3X OzUYjTyWXrNGzeQmxxtWPQL/b0F1v7rIZQXTw= Received: by 10.181.214.8 with SMTP id r8mr4057940bkq.206.1230316109046; Fri, 26 Dec 2008 10:28:29 -0800 (PST) Received: by 10.181.227.16 with HTTP; Fri, 26 Dec 2008 10:28:28 -0800 (PST) Message-ID: <5faa7b820812261028s7dd29063p47348abbf902c234@mail.gmail.com> Date: Fri, 26 Dec 2008 10:28:28 -0800 Sender: drwoland@gmail.com To: "Lukas Kahwe Smith" Cc: internals@lists.php.net In-Reply-To: <03D6160A-376F-44A8-B82F-F31873CFA0BB@pooteeweet.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_122995_1996258.1230316109040" References: <5faa7b820812260106p6f24bf0ct49ef574e5ed4e2c2@mail.gmail.com> <03D6160A-376F-44A8-B82F-F31873CFA0BB@pooteeweet.org> X-Google-Sender-Auth: 95cf084090feec87 Subject: Re: [PHP-DEV] Proposal: array_flatten function From: m@mihasya.com ("Mike Panchenko") ------=_Part_122995_1996258.1230316109040 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Lukas, Hmmm I'm just trying to solve the basic problem (hence my skepticism towards preserving keys - it seems an edge case). I think once you get to more specific requirements, iterators are probably the way to go, since all the standard functions you could use to shorten this would re-iterate over the array internally anyway. Cheers. Mike. On Fri, Dec 26, 2008 at 7:56 AM, Lukas Kahwe Smith wrote: > In one of my recent projects I had the need for something like this. I > essentially had a recursive data structure of organizations and frequently I > had to get a list of all organization ID's that were above or underneath a > given organization. So I had to write a deeply self join which would produce > lets say around 3-4 columns that either contained an ID or were NULL. > > I ended up with an implementation like the following. Actually looking at > it now it seems way too complex but it works, so it goes: > function flattenArray($array) { > if (empty($array)) { > return array(); > } > $first = reset($array); > if (empty($first)) { > return array(); > } > $keys = array_keys($first); > $result = array(); > foreach ($array as $row) { > foreach ($keys as $key) { > if (!empty($row[$key])) { > $result[] = $row[$key]; > } > } > } > $result = array_unique($result); > return $result; > } > > So I guess what I am asking for is a flag to ignore NULL's. Kind of reminds > me of that patch Igor proposed the other day. Then again, we have sooooo > many array functions its not even funny. So maybe we really should look more > towards Iterators to help us consolidate things. Not sure. > > regards, > Lukas > ------=_Part_122995_1996258.1230316109040--