FUDforum - خوراک RDF
http://fudforum.org/forum/index.php
how to join two arrays?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185704&th=123492#msg_185704
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.]]>Mr Oldies2014-05-03T17:25:10-00:00Re: how to join two arrays?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185710&th=123492#msg_185710
> 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]]>J.O. Aho2014-05-03T20:07:21-00:00Re: how to join two arrays?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185713&th=123492#msg_185713
> 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].
How you then tell which file is where, that's your headache at this point.
--
Denis McMahon, denismfmcmahon@gmail.com]]>Denis McMahon2014-05-03T22:23:29-00:00Re: how to join two arrays?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185714&th=123492#msg_185714
> 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]]>Thomas 'PointedEars' 2014-05-04T17:56:33-00:00Re: how to join two arrays?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185715&th=123492#msg_185715
> 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
==================]]>Jerry Stuckle2014-05-04T19:17:45-00:00Re: how to join two arrays?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185716&th=123492#msg_185716
> 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:
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]]>Thomas 'PointedEars' 2014-05-04T19:47:08-00:00Re: how to join two arrays?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185717&th=123492#msg_185717
> 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
==================]]>Jerry Stuckle2014-05-04T20:48:00-00:00Re: how to join two arrays?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185718&th=123492#msg_185718
> 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>]]>Thomas 'PointedEars' 2014-05-04T21:02:26-00:00Re: how to join two arrays?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185719&th=123492#msg_185719
> 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
==================]]>Jerry Stuckle2014-05-04T21:51:21-00:00Re: how to join two arrays?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185721&th=123492#msg_185721
> 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]]>Thomas 'PointedEars' 2014-05-04T22:55:16-00:00solved (was: how to join two arrays?)
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185722&th=123492#msg_185722
> 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.
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.]]>Mr Oldies2014-05-04T23:54:32-00:00Re: how to join two arrays?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185723&th=123492#msg_185723
> 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
==================]]>Jerry Stuckle2014-05-05T01:31:46-00:00Re: solved
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185724&th=123492#msg_185724
> 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.]]>Mr Oldies2014-05-05T02:00:27-00:00Re: how to join two arrays?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185725&th=123492#msg_185725
> 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
==================]]>Jerry Stuckle2014-05-05T02:13:32-00:00Re: solved
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185726&th=123492#msg_185726
> 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
==================]]>Jerry Stuckle2014-05-05T02:27:01-00:00Re: solved
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185727&th=123492#msg_185727
> 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.
> 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.]]>Ben Bacarisse2014-05-05T10:11:35-00:00Re: solved
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185729&th=123492#msg_185729
> On Sun, 04 May 2014 22:27:01 -0400, Jerry Stuckle wrote:
>> 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] !=".") {
As Ben pointed out, missing $ from [$x] in $files[x], but that's just
your usual broken code.
As it just increments the numeric index of $master by 1 each time it
assigns another element.
--
Denis McMahon, denismfmcmahon@gmail.com]]>Denis McMahon2014-05-05T13:36:57-00:00Re: solved
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185730&th=123492#msg_185730
> 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?]]>Mr Oldies2014-05-05T13:42:40-00:00Re: solved
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185731&th=123492#msg_185731
> 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]]>Christoph Michael Bec2014-05-05T13:51:44-00:00Re: solved
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185733&th=123492#msg_185733
> 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?
>
You're close. You want to add it if $file != "." AND $file != "..".
If $file equals ".", it cannot equal "..", and vice versa. So the test
you have is always true.
So what you want is
if ($file !== "." && $file !== "..")
....
--
==================
Remove the "x" from my email address
Jerry Stuckle jstucklex@attglobal.net
==================]]>Jerry Stuckle2014-05-05T14:26:51-00:00Re: solved
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185735&th=123492#msg_185735
> On 5/5/2014 9:42 AM, 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.
>>
>> Time to implement the formidable goto eh?
>>
>
> You're close. You want to add it if $file != "." AND $file != "..".
>
> If $file equals ".", it cannot equal "..", and vice versa. So the test
> you have is always true.
>
> So what you want is
>
> if ($file !== "." && $file !== "..")
> ...
thank you sir that worked perfectly.]]>Mr Oldies2014-05-05T14:34:09-00:00Re: how to join two arrays?
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185749&th=123492#msg_185749
<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!]]>Richard Yates2014-05-05T19:45:59-00:00Re: solved
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=185751&th=123492#msg_185751
noreply@example.com> wrote in news:1u66bqszrlp57$.2ce1bbokt163.dlg@
40tude.net:
[...]
> if ($file !== '.' || $file!=="..")
> $master[] = $file;
> This does not seem to work.
Depends on your definition of "work", I suppose. It definitely does work, in the sense that it
certainly is doing what you told it to. I'm pretty sure it's not doing what you expected it to do,
but that's because your expectations don't match your code.
Consider what happens when $file is equal to "." The first part of your compound condition
is FALSE. The second part is TRUE.
FALSE || TRUE is TRUE.
Now what happens when $file is equal to "..". The first part is TRUE, and the second part is
FALSE.
TRUE || FALSE is TRUE.
Finally, if $file is equal to, say, "abc". Now both parts of the condition are TRUE.
TRUE || TRUE is TRUE.
The results you *want* are FALSE, FALSE, TRUE respectively -- that is, you want the result
to be FALSE when *either* of its inputs is FALSE, and TRUE only if *both* of its inputs are
TRUE. That describes &&, not ||.
>
> Time to implement the formidable goto eh?
No, it's time to fix your broken logic. Google "De Morgan's Laws" for more information.]]>Doug Miller2014-05-06T00:55:46-00:00