Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #13492 > unrolled thread
| Started by | richard <noreply@example.com> |
|---|---|
| First post | 2014-05-03 13:25 -0400 |
| Last post | 2014-05-05 13:36 +0000 |
| Articles | 20 on this page of 24 — 9 participants |
Back to article view | Back to comp.lang.php
how to join two arrays? richard <noreply@example.com> - 2014-05-03 13:25 -0400
Re: how to join two arrays? "J.O. Aho" <user@example.net> - 2014-05-03 22:07 +0200
Re: how to join two arrays? Denis McMahon <denismfmcmahon@gmail.com> - 2014-05-03 22:23 +0000
Re: how to join two arrays? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-04 19:56 +0200
Re: how to join two arrays? Jerry Stuckle <jstucklex@attglobal.net> - 2014-05-04 15:17 -0400
Re: how to join two arrays? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-04 21:47 +0200
Re: how to join two arrays? Jerry Stuckle <jstucklex@attglobal.net> - 2014-05-04 16:48 -0400
Re: how to join two arrays? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-04 23:02 +0200
Re: how to join two arrays? Jerry Stuckle <jstucklex@attglobal.net> - 2014-05-04 17:51 -0400
Re: how to join two arrays? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-05 00:55 +0200
Re: how to join two arrays? Jerry Stuckle <jstucklex@attglobal.net> - 2014-05-04 21:31 -0400
Re: how to join two arrays? Jerry Stuckle <jstucklex@attglobal.net> - 2014-05-04 22:13 -0400
Re: how to join two arrays? Richard Yates <richard@yatesguitar.com> - 2014-05-05 12:45 -0700
solved (was: how to join two arrays?) richard <noreply@example.com> - 2014-05-04 19:54 -0400
Re: solved richard <noreply@example.com> - 2014-05-04 22:00 -0400
Re: solved Jerry Stuckle <jstucklex@attglobal.net> - 2014-05-04 22:27 -0400
Re: solved richard <noreply@example.com> - 2014-05-04 23:07 -0400
Re: solved Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-05-05 11:11 +0100
Re: solved richard <noreply@example.com> - 2014-05-05 09:42 -0400
Re: solved Christoph Michael Becker <cmbecker69@arcor.de> - 2014-05-05 15:51 +0200
Re: solved Jerry Stuckle <jstucklex@attglobal.net> - 2014-05-05 10:26 -0400
Re: solved richard <noreply@example.com> - 2014-05-05 10:34 -0400
Re: solved Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-05-06 00:55 +0000
Re: solved Denis McMahon <denismfmcmahon@gmail.com> - 2014-05-05 13:36 +0000
Page 1 of 2 [1] 2 Next page →
| From | richard <noreply@example.com> |
|---|---|
| Date | 2014-05-03 13:25 -0400 |
| Subject | how to join two arrays? |
| Message-ID | <1ma4780alja8r$.a7gtdehqwehf$.dlg@40tude.net> |
I am building an array by scannning ten directories. With each scanned directory, the output is stored in one array. How do I properly join that array with a second array? Without duplicate keys! Array_merge works fine but keys are duplicated.
[toc] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2014-05-03 22:07 +0200 |
| Message-ID | <bsl0jpFcv2nU1@mid.individual.net> |
| In reply to | #13492 |
On 03/05/14 19:25, richard wrote:
> I am building an array by scannning ten directories.
> With each scanned directory, the output is stored in one array.
> How do I properly join that array with a second array?
>
> Without duplicate keys!
>
> Array_merge works fine but keys are duplicated.
Keys are always unique, see example:
<?php
$a1 = array("a" => 1, "b" => 2, "c" => 3);
$a2 = array("a" => 10, "d" => 4, "e" => 5);
$a3 = array_merge($a1, $a2);
var_dump($a1);
var_dump($a2);
var_dump($a3);
echo $a3["a"]."\n";
?>
If you haven't named the cells, then it will just merge the arrays
(append one after the other).
--
//Aho
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-05-03 22:23 +0000 |
| Message-ID | <lk3q91$aom$4@dont-email.me> |
| In reply to | #13492 |
On Sat, 03 May 2014 13:25:10 -0400, richard wrote: > I am building an array by scannning ten directories. > With each scanned directory, the output is stored in one array. > How do I properly join that array with a second array? > > Without duplicate keys! > > Array_merge works fine but keys are duplicated. scandir creates numerically indexed arrays. Merging these arrays will create a larger numerically indexed array, eg if you merge two arrays with keys [0] through [9], you end up with a single array with keys [0] through [19]. eg if the first dir generated: $arr1 [0] "." [1] ".." [2] "foo.bar" [3] "really fubar" and the second dir generated $arr2 [0] "." [1] ".." [2] "bah bah.blacksheep" [3] "fufu.fubar" then: array_merge ( $arr1, $arr2 ); will generate: [0] "." [1] ".." [2] "foo.bar" [3] "really fubar" [4] "." [5] ".." [6] "bah bah.blacksheep" [7] "fufu.fubar" How you then tell which file is where, that's your headache at this point. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-05-04 19:56 +0200 |
| Message-ID | <7972885.Ly6agpYKli@PointedEars.de> |
| In reply to | #13501 |
Denis McMahon wrote: > then: array_merge ( $arr1, $arr2 ); > > will generate: > > [0] "." > [1] ".." > [2] "foo.bar" > [3] "really fubar" > [4] "." > [5] ".." > [6] "bah bah.blacksheep" > [7] "fufu.fubar" > > How you then tell which file is where, that's your headache at this point. array_map() serves here. PointedEars -- > If you get a bunch of authors […] that state the same "best practices" > in any programming language, then you can bet who is wrong or right... Not with javascript. Nonsense propagates like wildfire in this field. -- Richard Cornford, comp.lang.javascript, 2011-11-14
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2014-05-04 15:17 -0400 |
| Message-ID | <lk63ol$44c$1@dont-email.me> |
| In reply to | #13502 |
On 5/4/2014 1:56 PM, Thomas 'PointedEars' Lahn wrote: > Denis McMahon wrote: > >> then: array_merge ( $arr1, $arr2 ); >> >> will generate: >> >> [0] "." >> [1] ".." >> [2] "foo.bar" >> [3] "really fubar" >> [4] "." >> [5] ".." >> [6] "bah bah.blacksheep" >> [7] "fufu.fubar" >> >> How you then tell which file is where, that's your headache at this point. > > array_map() serves here. > > > PointedEars > And how can array_map() tell which file is where? -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-05-04 21:47 +0200 |
| Message-ID | <4250025.snfbUPKjyN@PointedEars.de> |
| In reply to | #13503 |
Jerry Stuckle wrote:
> On 5/4/2014 1:56 PM, Thomas 'PointedEars' Lahn wrote:
>> Denis McMahon wrote:
>>> then: array_merge ( $arr1, $arr2 );
>>>
>>> will generate:
>>>
>>> [0] "."
>>> [1] ".."
>>> [2] "foo.bar"
>>> [3] "really fubar"
>>> [4] "."
>>> [5] ".."
>>> [6] "bah bah.blacksheep"
>>> [7] "fufu.fubar"
>>>
>>> How you then tell which file is where, that's your headache at this
>>> point.
>>
>> array_map() serves here.
>
> And how can array_map() tell which file is where?
It cannot. However, if you apply array_map() to the arrays returned by
scandir() before merging them, the problem at hand does not occur in the
first place:
$modi = max(
array_map('filemtime',
array_diff(
array_merge(
scandir(__DIR__),
array_map(
function ($e) {
return 'sections' . DIRECTORY_SEPARATOR . $e;
},
scandir('sections')
)
),
array('.', '..')
)
)
);
HTH
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2014-05-04 16:48 -0400 |
| Message-ID | <lk691r$9ku$1@dont-email.me> |
| In reply to | #13504 |
On 5/4/2014 3:47 PM, Thomas 'PointedEars' Lahn wrote:
> Jerry Stuckle wrote:
>
>> On 5/4/2014 1:56 PM, Thomas 'PointedEars' Lahn wrote:
>>> Denis McMahon wrote:
>>>> then: array_merge ( $arr1, $arr2 );
>>>>
>>>> will generate:
>>>>
>>>> [0] "."
>>>> [1] ".."
>>>> [2] "foo.bar"
>>>> [3] "really fubar"
>>>> [4] "."
>>>> [5] ".."
>>>> [6] "bah bah.blacksheep"
>>>> [7] "fufu.fubar"
>>>>
>>>> How you then tell which file is where, that's your headache at this
>>>> point.
>>>
>>> array_map() serves here.
>>
>> And how can array_map() tell which file is where?
>
> It cannot.
Then why did you say it could?
However, if you apply array_map() to the arrays returned by
> scandir() before merging them, the problem at hand does not occur in the
> first place:
>
> $modi = max(
> array_map('filemtime',
> array_diff(
> array_merge(
> scandir(__DIR__),
> array_map(
> function ($e) {
> return 'sections' . DIRECTORY_SEPARATOR . $e;
> },
> scandir('sections')
> )
> ),
> array('.', '..')
> )
> )
> );
>
>
> HTH
>
> PointedEars
>
What a convoluted mess. Glad you're not working on any code I have to
touch!
But then you always did have a knack for making a mountain out of a
molehill.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-05-04 23:02 +0200 |
| Message-ID | <1620039.UmlCRpQXXg@PointedEars.de> |
| In reply to | #13505 |
Jerry Stuckle wrote: > On 5/4/2014 3:47 PM, Thomas 'PointedEars' Lahn wrote: >> Jerry Stuckle wrote: >>> On 5/4/2014 1:56 PM, Thomas 'PointedEars' Lahn wrote: >>>> Denis McMahon wrote: >>>>> then: array_merge ( $arr1, $arr2 ); >>>>> >>>>> will generate: >>>>> >>>>> [0] "." >>>>> [1] ".." >>>>> [2] "foo.bar" >>>>> [3] "really fubar" >>>>> [4] "." >>>>> [5] ".." >>>>> [6] "bah bah.blacksheep" >>>>> [7] "fufu.fubar" >>>>> >>>>> How you then tell which file is where, that's your headache at this >>>>> point. >>>> >>>> array_map() serves here. >>> >>> And how can array_map() tell which file is where? >> >> It cannot. > > Then why did you say it could? I did not. PointedEars -- Prototype.js was written by people who don't know javascript for people who don't know javascript. People who don't know javascript are not the best source of advice on designing systems that use javascript. -- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2014-05-04 17:51 -0400 |
| Message-ID | <lk6cok$1rp$1@dont-email.me> |
| In reply to | #13506 |
On 5/4/2014 5:02 PM, Thomas 'PointedEars' Lahn wrote: > Jerry Stuckle wrote: > >> On 5/4/2014 3:47 PM, Thomas 'PointedEars' Lahn wrote: >>> Jerry Stuckle wrote: >>>> On 5/4/2014 1:56 PM, Thomas 'PointedEars' Lahn wrote: >>>>> Denis McMahon wrote: >>>>>> then: array_merge ( $arr1, $arr2 ); >>>>>> >>>>>> will generate: >>>>>> >>>>>> [0] "." >>>>>> [1] ".." >>>>>> [2] "foo.bar" >>>>>> [3] "really fubar" >>>>>> [4] "." >>>>>> [5] ".." >>>>>> [6] "bah bah.blacksheep" >>>>>> [7] "fufu.fubar" >>>>>> >>>>>> How you then tell which file is where, that's your headache at this >>>>>> point. >>>>> >>>>> array_map() serves here. >>>> >>>> And how can array_map() tell which file is where? >>> >>> It cannot. >> >> Then why did you say it could? > > I did not. > > > PointedEars > You can't even read what you wrote... Even though it's part of this message above, I'll repeat it for you: >> How you then tell which file is where, that's your headache at this >> point. > > array_map() serves here. -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-05-05 00:55 +0200 |
| Message-ID | <5757340.TZ9IJtgvlb@PointedEars.de> |
| In reply to | #13507 |
Jerry Stuckle wrote: > On 5/4/2014 5:02 PM, Thomas 'PointedEars' Lahn wrote: >> Jerry Stuckle wrote: >>> On 5/4/2014 3:47 PM, Thomas 'PointedEars' Lahn wrote: >>>> Jerry Stuckle wrote: >>>>> On 5/4/2014 1:56 PM, Thomas 'PointedEars' Lahn wrote: >>>>>> Denis McMahon wrote: >>>>>>> then: array_merge ( $arr1, $arr2 ); >>>>>>> >>>>>>> will generate: >>>>>>> >>>>>>> [0] "." >>>>>>> [1] ".." >>>>>>> [2] "foo.bar" >>>>>>> [3] "really fubar" >>>>>>> [4] "." >>>>>>> [5] ".." >>>>>>> [6] "bah bah.blacksheep" >>>>>>> [7] "fufu.fubar" >>>>>>> >>>>>>> How you then tell which file is where, that's your headache at this >>>>>>> point. >>>>>> array_map() serves here. >>>>> And how can array_map() tell which file is where? >>>> It cannot. >>> Then why did you say it could? >> I did not. > > You can't even read what you wrote... I know what I wrote. I also know that – granting you the benefit of a doubt one more time – you are not trolling, but that you have misinterpreted what I wrote. I have written (as can be read in the quotation above, so there is no need for you or me to repeat it below) that “array_map() serves here”. It does. I have, upon your query, given an example showing what I meant with “serves here” from a real-life example (hence “here”). Apparently you have not bothered to understand the example, as you had decided to deride it in yet another ad-hominem fallacy of yours. I have made myself clear now to all who can read carefully and think clearly. Further misinterpretation on your part will be considered deliberate, aka trolling, and dealt with accordingly. HTH PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2014-05-04 21:31 -0400 |
| Message-ID | <lk6plv$aau$1@dont-email.me> |
| In reply to | #13508 |
On 5/4/2014 6:55 PM, Thomas 'PointedEars' Lahn wrote: > Jerry Stuckle wrote: > >> On 5/4/2014 5:02 PM, Thomas 'PointedEars' Lahn wrote: >>> Jerry Stuckle wrote: >>>> On 5/4/2014 3:47 PM, Thomas 'PointedEars' Lahn wrote: >>>>> Jerry Stuckle wrote: >>>>>> On 5/4/2014 1:56 PM, Thomas 'PointedEars' Lahn wrote: >>>>>>> Denis McMahon wrote: >>>>>>>> then: array_merge ( $arr1, $arr2 ); >>>>>>>> >>>>>>>> will generate: >>>>>>>> >>>>>>>> [0] "." >>>>>>>> [1] ".." >>>>>>>> [2] "foo.bar" >>>>>>>> [3] "really fubar" >>>>>>>> [4] "." >>>>>>>> [5] ".." >>>>>>>> [6] "bah bah.blacksheep" >>>>>>>> [7] "fufu.fubar" >>>>>>>> >>>>>>>> How you then tell which file is where, that's your headache at this >>>>>>>> point. >>>>>>> array_map() serves here. >>>>>> And how can array_map() tell which file is where? >>>>> It cannot. >>>> Then why did you say it could? >>> I did not. >> >> You can't even read what you wrote... > > I know what I wrote. I also know that – granting you the benefit of a > doubt one more time – you are not trolling, but that you have misinterpreted > what I wrote. I have written (as can be read in the quotation above, so > there is no need for you or me to repeat it below) that “array_map() serves > here”. It does. I have, upon your query, given an example showing what I > meant with “serves here” from a real-life example (hence “here”). > Apparently you have not bothered to understand the example, as you had > decided to deride it in yet another ad-hominem fallacy of yours. > > I have made myself clear now to all who can read carefully and think > clearly. Further misinterpretation on your part will be considered > deliberate, aka trolling, and dealt with accordingly. > > > HTH > > PointedEars > There was nothing to misinterpret. array_map() does Not solve the problem of "How you then tell which file is where, that's your headache at this point.", which is the question it is response to. But we already know you're too stoopid to understand, and too egotistical to admit you screwed up (again). And yes, you made yourself clear. You proved you have no idea how to solve this problem. So, do everyone a favor and find another newsgroup to troll. You're know as one in enough newsgroups that shouldn't be a problem. As for suggestion someone else is a troll? That is the best laugh I've heard of all year. It's even better than suggesting Richard is competent. -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2014-05-04 22:13 -0400 |
| Message-ID | <lk6s47$kuc$1@dont-email.me> |
| In reply to | #13510 |
On 5/4/2014 9:31 PM, Jerry Stuckle wrote: > On 5/4/2014 6:55 PM, Thomas 'PointedEars' Lahn wrote: >> Jerry Stuckle wrote: >> >>> On 5/4/2014 5:02 PM, Thomas 'PointedEars' Lahn wrote: >>>> Jerry Stuckle wrote: >>>>> On 5/4/2014 3:47 PM, Thomas 'PointedEars' Lahn wrote: >>>>>> Jerry Stuckle wrote: >>>>>>> On 5/4/2014 1:56 PM, Thomas 'PointedEars' Lahn wrote: >>>>>>>> Denis McMahon wrote: >>>>>>>>> then: array_merge ( $arr1, $arr2 ); >>>>>>>>> >>>>>>>>> will generate: >>>>>>>>> >>>>>>>>> [0] "." >>>>>>>>> [1] ".." >>>>>>>>> [2] "foo.bar" >>>>>>>>> [3] "really fubar" >>>>>>>>> [4] "." >>>>>>>>> [5] ".." >>>>>>>>> [6] "bah bah.blacksheep" >>>>>>>>> [7] "fufu.fubar" >>>>>>>>> >>>>>>>>> How you then tell which file is where, that's your headache at >>>>>>>>> this >>>>>>>>> point. >>>>>>>> array_map() serves here. >>>>>>> And how can array_map() tell which file is where? >>>>>> It cannot. >>>>> Then why did you say it could? >>>> I did not. >>> >>> You can't even read what you wrote... >> >> I know what I wrote. I also know that – granting you the benefit of a >> doubt one more time – you are not trolling, but that you have >> misinterpreted >> what I wrote. I have written (as can be read in the quotation above, so >> there is no need for you or me to repeat it below) that “array_map() >> serves >> here”. It does. I have, upon your query, given an example showing >> what I >> meant with “serves here” from a real-life example (hence “here”). >> Apparently you have not bothered to understand the example, as you had >> decided to deride it in yet another ad-hominem fallacy of yours. >> >> I have made myself clear now to all who can read carefully and think >> clearly. Further misinterpretation on your part will be considered >> deliberate, aka trolling, and dealt with accordingly. >> >> >> HTH >> >> PointedEars >> > > There was nothing to misinterpret. array_map() does Not solve the > problem of "How you then tell which file is where, that's your headache > at this point.", which is the question it is response to. > > But we already know you're too stoopid to understand, and too > egotistical to admit you screwed up (again). > > And yes, you made yourself clear. You proved you have no idea how to > solve this problem. > > So, do everyone a favor and find another newsgroup to troll. You're > know as one in enough newsgroups that shouldn't be a problem. > > As for suggestion someone else is a troll? That is the best laugh I've > heard of all year. It's even better than suggesting Richard is competent. > > Looking over my last comment, I have to apologize. It wasn't fair to Richard. Sorry, Richard, I shouldn't have insulted you like that. -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Richard Yates <richard@yatesguitar.com> |
|---|---|
| Date | 2014-05-05 12:45 -0700 |
| Message-ID | <3jqfm9t1dlhulslduc3h2e703mol68dnvo@4ax.com> |
| In reply to | #13512 |
On Sun, 04 May 2014 22:13:32 -0400, Jerry Stuckle <jstucklex@attglobal.net> wrote: >On 5/4/2014 9:31 PM, Jerry Stuckle wrote: >> On 5/4/2014 6:55 PM, Thomas 'PointedEars' Lahn wrote: >>> Jerry Stuckle wrote: >>> >>>> On 5/4/2014 5:02 PM, Thomas 'PointedEars' Lahn wrote: >>>>> Jerry Stuckle wrote: >>>>>> On 5/4/2014 3:47 PM, Thomas 'PointedEars' Lahn wrote: >>>>>>> Jerry Stuckle wrote: >>>>>>>> On 5/4/2014 1:56 PM, Thomas 'PointedEars' Lahn wrote: >>>>>>>>> Denis McMahon wrote: >>>>>>>>>> then: array_merge ( $arr1, $arr2 ); >>>>>>>>>> >>>>>>>>>> will generate: >>>>>>>>>> >>>>>>>>>> [0] "." >>>>>>>>>> [1] ".." >>>>>>>>>> [2] "foo.bar" >>>>>>>>>> [3] "really fubar" >>>>>>>>>> [4] "." >>>>>>>>>> [5] ".." >>>>>>>>>> [6] "bah bah.blacksheep" >>>>>>>>>> [7] "fufu.fubar" >>>>>>>>>> >>>>>>>>>> How you then tell which file is where, that's your headache at >>>>>>>>>> this >>>>>>>>>> point. >>>>>>>>> array_map() serves here. >>>>>>>> And how can array_map() tell which file is where? >>>>>>> It cannot. >>>>>> Then why did you say it could? >>>>> I did not. >>>> >>>> You can't even read what you wrote... >>> >>> I know what I wrote. I also know that – granting you the benefit of a >>> doubt one more time – you are not trolling, but that you have >>> misinterpreted >>> what I wrote. I have written (as can be read in the quotation above, so >>> there is no need for you or me to repeat it below) that “array_map() >>> serves >>> here”. It does. I have, upon your query, given an example showing >>> what I >>> meant with “serves here” from a real-life example (hence “here”). >>> Apparently you have not bothered to understand the example, as you had >>> decided to deride it in yet another ad-hominem fallacy of yours. >>> >>> I have made myself clear now to all who can read carefully and think >>> clearly. Further misinterpretation on your part will be considered >>> deliberate, aka trolling, and dealt with accordingly. >>> >>> >>> HTH >>> >>> PointedEars >>> >> >> There was nothing to misinterpret. array_map() does Not solve the >> problem of "How you then tell which file is where, that's your headache >> at this point.", which is the question it is response to. >> >> But we already know you're too stoopid to understand, and too >> egotistical to admit you screwed up (again). >> >> And yes, you made yourself clear. You proved you have no idea how to >> solve this problem. >> >> So, do everyone a favor and find another newsgroup to troll. You're >> know as one in enough newsgroups that shouldn't be a problem. >> >> As for suggestion someone else is a troll? That is the best laugh I've >> heard of all year. It's even better than suggesting Richard is competent. >> >> > >Looking over my last comment, I have to apologize. It wasn't fair to >Richard. Sorry, Richard, I shouldn't have insulted you like that. Case sensitivity please!
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2014-05-04 19:54 -0400 |
| Subject | solved (was: how to join two arrays?) |
| Message-ID | <16xq2nliyxm0r.1pydq2jo6js8c$.dlg@40tude.net> |
| In reply to | #13492 |
On Sat, 3 May 2014 13:25:10 -0400, richard wrote:
> I am building an array by scannning ten directories.
> With each scanned directory, the output is stored in one array.
> How do I properly join that array with a second array?
>
> Without duplicate keys!
>
> Array_merge works fine but keys are duplicated.
$lo=0;
$hi=0;
for ($i = 59; $i <= 69; $i++) {
$yr="19$i";
echo $i;
echo $yr;
echo "<br>";
$dir='../audio/'.$yr.'/';
$files = scandir($dir);
$number=count($files);
echo $number;
echo "<br>";
sort($files);
$hi=$hi+$number;
echo $hi;
echo "<br>";
for ($x=0;$x<=$number;$x++){echo $files[$x];
$master[$lo]=$files[$x];
$lo=$lo+1;
}
$lo=$hi;
}
for ($x=0;$x<=$hi;$x++){echo $master[$x]."<br>";}
the echos are there primarily to show what the progress is.
they will be removed for final output.
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2014-05-04 22:00 -0400 |
| Subject | Re: solved |
| Message-ID | <5oo9jupriqe6$.zu9bt3msqine.dlg@40tude.net> |
| In reply to | #13509 |
On Sun, 4 May 2014 19:54:32 -0400, richard wrote:
> On Sat, 3 May 2014 13:25:10 -0400, richard wrote:
>
>> I am building an array by scannning ten directories.
>> With each scanned directory, the output is stored in one array.
>> How do I properly join that array with a second array?
>>
>> Without duplicate keys!
>>
>> Array_merge works fine but keys are duplicated.
>
>
> $lo=0;
> $hi=0;
>
> for ($i = 59; $i <= 69; $i++) {
> $yr="19$i";
> echo $i;
> echo $yr;
> echo "<br>";
>
> $dir='../audio/'.$yr.'/';
> $files = scandir($dir);
> $number=count($files);
> echo $number;
> echo "<br>";
> sort($files);
> $hi=$hi+$number;
> echo $hi;
> echo "<br>";
>
> for ($x=0;$x<=$number;$x++){echo $files[$x];
> $master[$lo]=$files[$x];
> $lo=$lo+1;
>
> }
> $lo=$hi;
> }
>
> for ($x=0;$x<=$hi;$x++){echo $master[$x]."<br>";}
>
> the echos are there primarily to show what the progress is.
> they will be removed for final output.
Questio I have now is, how do I get it so the leading "." and ".." are not
in the final array?
I tried using a conditional with !="." and that did not work.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2014-05-04 22:27 -0400 |
| Subject | Re: solved |
| Message-ID | <lk6sti$pff$1@dont-email.me> |
| In reply to | #13511 |
On 5/4/2014 10:00 PM, richard wrote:
> On Sun, 4 May 2014 19:54:32 -0400, richard wrote:
>
>> On Sat, 3 May 2014 13:25:10 -0400, richard wrote:
>>
>>> I am building an array by scannning ten directories.
>>> With each scanned directory, the output is stored in one array.
>>> How do I properly join that array with a second array?
>>>
>>> Without duplicate keys!
>>>
>>> Array_merge works fine but keys are duplicated.
>>
>>
>> $lo=0;
>> $hi=0;
>>
>> for ($i = 59; $i <= 69; $i++) {
>> $yr="19$i";
>> echo $i;
>> echo $yr;
>> echo "<br>";
>>
>> $dir='../audio/'.$yr.'/';
>> $files = scandir($dir);
>> $number=count($files);
>> echo $number;
>> echo "<br>";
>> sort($files);
>> $hi=$hi+$number;
>> echo $hi;
>> echo "<br>";
>>
>> for ($x=0;$x<=$number;$x++){echo $files[$x];
>> $master[$lo]=$files[$x];
>> $lo=$lo+1;
>>
>> }
>> $lo=$hi;
>> }
>>
>> for ($x=0;$x<=$hi;$x++){echo $master[$x]."<br>";}
>>
>> the echos are there primarily to show what the progress is.
>> they will be removed for final output.
>
> Questio I have now is, how do I get it so the leading "." and ".." are not
> in the final array?
> I tried using a conditional with !="." and that did not work.
>
Richard,
If written correctly a conditional for !="." would get rid of the '.'
entry; !=".." would get rid of the ".." entry.
But you didn't show your entire code, so it's hard to say what could be
wrong.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2014-05-04 23:07 -0400 |
| Subject | Re: solved |
| Message-ID | <57n6x3z90tu3.19j4qnzkwif2b.dlg@40tude.net> |
| In reply to | #13513 |
On Sun, 04 May 2014 22:27:01 -0400, Jerry Stuckle wrote:
> On 5/4/2014 10:00 PM, richard wrote:
>> On Sun, 4 May 2014 19:54:32 -0400, richard wrote:
>>
>>> On Sat, 3 May 2014 13:25:10 -0400, richard wrote:
>>>
>>>> I am building an array by scannning ten directories.
>>>> With each scanned directory, the output is stored in one array.
>>>> How do I properly join that array with a second array?
>>>>
>>>> Without duplicate keys!
>>>>
>>>> Array_merge works fine but keys are duplicated.
>>>
>>>
>>> $lo=0;
>>> $hi=0;
>>>
>>> for ($i = 59; $i <= 69; $i++) {
>>> $yr="19$i";
>>> echo $i;
>>> echo $yr;
>>> echo "<br>";
>>>
>>> $dir='../audio/'.$yr.'/';
>>> $files = scandir($dir);
>>> $number=count($files);
>>> echo $number;
>>> echo "<br>";
>>> sort($files);
>>> $hi=$hi+$number;
>>> echo $hi;
>>> echo "<br>";
>>>
>>> for ($x=0;$x<=$number;$x++){echo $files[$x];
>>> $master[$lo]=$files[$x];
>>> $lo=$lo+1;
>>>
>>> }
>>> $lo=$hi;
>>> }
>>>
>>> for ($x=0;$x<=$hi;$x++){echo $master[$x]."<br>";}
>>>
>>> the echos are there primarily to show what the progress is.
>>> they will be removed for final output.
>>
>> Questio I have now is, how do I get it so the leading "." and ".." are not
>> in the final array?
>> I tried using a conditional with !="." and that did not work.
>>
>
> Richard,
>
> If written correctly a conditional for !="." would get rid of the '.'
> entry; !=".." would get rid of the ".." entry.
>
> But you didn't show your entire code, so it's hard to say what could be
> wrong.
for ($x=0;$x<=$number;$x++){
if ($files[x] !=".") {
$master[$lo]=$files[$x];
$lo=$lo+1;
}
}
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2014-05-05 11:11 +0100 |
| Subject | Re: solved |
| Message-ID | <0.71dc8625665581959ca2.20140505111135BST.87iopkv8ko.fsf@bsb.me.uk> |
| In reply to | #13514 |
richard <noreply@example.com> writes:
> On Sun, 04 May 2014 22:27:01 -0400, Jerry Stuckle wrote:
<snip>
>> But you didn't show your entire code, so it's hard to say what could be
>> wrong.
>
> for ($x=0;$x<=$number;$x++){
>
> if ($files[x] !=".") {
^ not $x
> $master[$lo]=$files[$x];
> $lo=$lo+1;
> }
> }
You really need to find some what to work which lets you see all the
notices and warnings that PHP can give you.
By the way, writing $master[] = ... puts an element at the next unused
numerical index in the array which might be what you are doing here with
$lo. I'd write the above like this:
foreach ($files as $file)
if ($file !== '.')
$master[] = $file;
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2014-05-05 09:42 -0400 |
| Subject | Re: solved |
| Message-ID | <1u66bqszrlp57$.2ce1bbokt163.dlg@40tude.net> |
| In reply to | #13515 |
On Mon, 05 May 2014 11:11:35 +0100, Ben Bacarisse wrote:
> richard <noreply@example.com> writes:
>
>> On Sun, 04 May 2014 22:27:01 -0400, Jerry Stuckle wrote:
> <snip>
>>> But you didn't show your entire code, so it's hard to say what could be
>>> wrong.
>>
>> for ($x=0;$x<=$number;$x++){
>>
>> if ($files[x] !=".") {
> ^ not $x
>
>> $master[$lo]=$files[$x];
>> $lo=$lo+1;
>> }
>> }
>
> You really need to find some what to work which lets you see all the
> notices and warnings that PHP can give you.
>
> By the way, writing $master[] = ... puts an element at the next unused
> numerical index in the array which might be what you are doing here with
> $lo. I'd write the above like this:
>
> foreach ($files as $file)
> if ($file !== '.')
> $master[] = $file;
Thanks. Works like a charm.
Now how do I also include the ".."?
foreach ($files as $file)
if ($file !== '.' || $file!=="..")
$master[] = $file;
This does not seem to work.
Time to implement the formidable goto eh?
[toc] | [prev] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-05-05 15:51 +0200 |
| Subject | Re: solved |
| Message-ID | <5367976e$0$6719$9b4e6d93@newsspool3.arcor-online.net> |
| In reply to | #13517 |
richard wrote:
> On Mon, 05 May 2014 11:11:35 +0100, Ben Bacarisse wrote:
>
>> richard <noreply@example.com> writes:
>>
>>> On Sun, 04 May 2014 22:27:01 -0400, Jerry Stuckle wrote:
>> <snip>
>>>> But you didn't show your entire code, so it's hard to say what could be
>>>> wrong.
>>>
>>> for ($x=0;$x<=$number;$x++){
>>>
>>> if ($files[x] !=".") {
>> ^ not $x
>>
>>> $master[$lo]=$files[$x];
>>> $lo=$lo+1;
>>> }
>>> }
>>
>> You really need to find some what to work which lets you see all the
>> notices and warnings that PHP can give you.
>>
>> By the way, writing $master[] = ... puts an element at the next unused
>> numerical index in the array which might be what you are doing here with
>> $lo. I'd write the above like this:
>>
>> foreach ($files as $file)
>> if ($file !== '.')
>> $master[] = $file;
>
> Thanks. Works like a charm.
> Now how do I also include the ".."?
> foreach ($files as $file)
> if ($file !== '.' || $file!=="..")
> $master[] = $file;
> This does not seem to work.
I assume that it does what it should: it will append any file whose name
is not equal to '.' *or* not equal to '..', i.e. every file. You want
to use the && operator here.
Another option which excludes all hidden files:
if ($file[0] != '.')
> Time to implement the formidable goto eh?
Fortunately not.
--
Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.php
csiph-web