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


Groups > comp.lang.php > #11821 > unrolled thread

array search part 2

Started byrichard <noreply@example.com>
First post2013-11-18 09:10 -0500
Last post2013-11-20 16:02 +0100
Articles 10 on this page of 30 — 14 participants

Back to article view | Back to comp.lang.php


Contents

  array search part 2 richard <noreply@example.com> - 2013-11-18 09:10 -0500
    Re: array search part 2 Christoph Michael Becker <cmbecker69@arcor.de> - 2013-11-18 15:32 +0100
      Re: array search part 2 richard <noreply@example.com> - 2013-11-18 09:59 -0500
    Re: array search part 2 richard <noreply@example.com> - 2013-11-18 09:31 -0500
    Re: array search part 2 Tim Streater <timstreater@greenbee.net> - 2013-11-18 15:05 +0000
      Re: array search part 2 richard <noreply@example.com> - 2013-11-18 11:06 -0500
        Re: array search part 2 Christoph Michael Becker <cmbecker69@arcor.de> - 2013-11-18 17:17 +0100
        Re: array search part 2 "Peter H. Coffin" <hellsop@ninehells.com> - 2013-11-18 11:08 -0600
        Re: array search part 2 Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-11-19 03:11 +0000
        Re: array search part 2 Arno Welzel <usenet@arnowelzel.de> - 2013-11-19 09:27 +0100
      Re: array search part 2 Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-18 13:08 -0500
    Re: array search part 2 richard <noreply@example.com> - 2013-11-18 11:11 -0500
      Re: array search part 2 "J.O. Aho" <user@example.net> - 2013-11-18 19:10 +0100
        Re: array search part 2 Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-18 18:28 +0000
          Re: array search part 2 "J.O. Aho" <user@example.net> - 2013-11-18 20:03 +0100
    solved  (was: array search part 2) richard <noreply@example.com> - 2013-11-18 21:45 -0500
      Re: solved Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-19 13:50 +0000
        Re: solved Scott Johnson <noonehome@chalupasworld.com> - 2013-11-19 06:16 -0800
          Re: solved Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-19 16:29 +0000
            Re: solved Scott Johnson <noonehome@chalupasworld.com> - 2013-11-19 10:57 -0800
        Re: solved tony@mountifield.org (Tony Mountifield) - 2013-11-19 14:48 +0000
          Re: solved Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-19 16:12 +0100
          Re: solved Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-19 16:25 +0000
        Re: solved richard <noreply@example.com> - 2013-11-19 11:51 -0500
          Re: solved Christoph Michael Becker <cmbecker69@arcor.de> - 2013-11-19 18:31 +0100
          Re: solved Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-11-19 18:15 +0000
      Re: solved Arno Welzel <usenet@arnowelzel.de> - 2013-11-19 17:43 +0100
        Re: solved richard <noreply@example.com> - 2013-11-19 14:41 -0500
          Re: solved "Beauregard T. Shagnasty" <a.nony.mous@example.invalid> - 2013-11-19 19:52 +0000
          Re: solved Arno Welzel <usenet@arnowelzel.de> - 2013-11-20 16:02 +0100

Page 2 of 2 — ← Prev page 1 [2]


#11861 — Re: solved

Fromtony@mountifield.org (Tony Mountifield)
Date2013-11-19 14:48 +0000
SubjectRe: solved
Message-ID<l6ftns$g73$1@softins.softins.co.uk>
In reply to#11859
In article <0.7dbacdb97db2593ac9fc.20131119135002GMT.87bo1gpkl1.fsf@bsb.me.uk>,
Ben Bacarisse  <ben.usenet@bsb.me.uk> wrote:
> richard <noreply@example.com> writes:
> 
> > <?php
> >
> > $track=$_GET['item'];
> >
> >
> > $asong=$six0[$track][0];
> > $flip=$six0[$track][1];
> >
> > $max=count($six0);
> >
> > $match=0;
> >
> > for ($item=0;$item<=$max;$item++){
> > if ($flip==$six0[$item]['0'])
> >   {if ($six0[$item][2]=$six0[$track][2])
> 
> There's no need to assign something to itself just to test it.

It's not being assigned to itself. The destination is indexed by $item
and the source is indexed by $track.

Cheers
Tony
-- 
Tony Mountifield
Work: tony@softins.co.uk - http://www.softins.co.uk
Play: tony@mountifield.org - http://tony.mountifield.org

[toc] | [prev] | [next] | [standalone]


#11862 — Re: solved

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-11-19 16:12 +0100
SubjectRe: solved
Message-ID<2055690.DL4N1axar6@PointedEars.de>
In reply to#11861
Tony Mountifield wrote:

> Ben Bacarisse  <ben.usenet@bsb.me.uk> wrote:
>> richard <noreply@example.com> writes:
>> > <?php
>> >
>> > $track=$_GET['item'];
>> >
>> >
>> > $asong=$six0[$track][0];
>> > $flip=$six0[$track][1];
>> >
>> > $max=count($six0);
>> >
>> > $match=0;
>> >
>> > for ($item=0;$item<=$max;$item++){
>> > if ($flip==$six0[$item]['0'])
>> >   {if ($six0[$item][2]=$six0[$track][2])
>> 
>> There's no need to assign something to itself just to test it.
> 
> It's not being assigned to itself. The destination is indexed by $item
> and the source is indexed by $track.

It is still richard^Wnonsense.


PointedEars
-- 
When all you know is jQuery, every problem looks $(olvable).

[toc] | [prev] | [next] | [standalone]


#11863 — Re: solved

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-11-19 16:25 +0000
SubjectRe: solved
Message-ID<0.ccd562a6b6f2a6cc90c5.20131119162547GMT.87li0knyt0.fsf@bsb.me.uk>
In reply to#11861
tony@mountifield.org (Tony Mountifield) writes:

> In article <0.7dbacdb97db2593ac9fc.20131119135002GMT.87bo1gpkl1.fsf@bsb.me.uk>,
> Ben Bacarisse  <ben.usenet@bsb.me.uk> wrote:
>> richard <noreply@example.com> writes:
<snip>
>> > for ($item=0;$item<=$max;$item++){
>> > if ($flip==$six0[$item]['0'])
>> >   {if ($six0[$item][2]=$six0[$track][2])
>> 
>> There's no need to assign something to itself just to test it.
>
> It's not being assigned to itself. The destination is indexed by $item
> and the source is indexed by $track.

Good spot, thanks.  I wonder if that was intended.  Probably not.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#11866 — Re: solved

Fromrichard <noreply@example.com>
Date2013-11-19 11:51 -0500
SubjectRe: solved
Message-ID<20a7y175syne$.gwvfdueii11x.dlg@40tude.net>
In reply to#11859
On Tue, 19 Nov 2013 13:50:02 +0000, Ben Bacarisse wrote:

> richard <noreply@example.com> writes:
> 
>> <?php
>>
>> $track=$_GET['item'];
>>
>>
>> $asong=$six0[$track][0];
>> $flip=$six0[$track][1];
>>
>> $max=count($six0);
>>
>> $match=0;
>>
>> for ($item=0;$item<=$max;$item++){
>> if ($flip==$six0[$item]['0'])
>>   {if ($six0[$item][2]=$six0[$track][2])
> 
> There's no need to assign something to itself just to test it.  The
> test:
> 

If you'd bother to comprehend what is happening, it is not assigning
itself.
$item is the value derived from the loop.
$track is the fixed valued assigned at the time of $_GET.
so if $item and $track are equal then the statement is true and the result
assigns the value to $match and that is what is used to display the proper
item.

If $track=1 and $item=101 and the pairs match in value, then $match gets
the number to use.

[toc] | [prev] | [next] | [standalone]


#11867 — Re: solved

FromChristoph Michael Becker <cmbecker69@arcor.de>
Date2013-11-19 18:31 +0100
SubjectRe: solved
Message-ID<528ba05c$0$9502$9b4e6d93@newsspool1.arcor-online.net>
In reply to#11866
richard wrote:

> On Tue, 19 Nov 2013 13:50:02 +0000, Ben Bacarisse wrote:
> 
>> richard <noreply@example.com> writes:
>>
>>> <?php
>>>
>>> $track=$_GET['item'];
>>>
>>>
>>> $asong=$six0[$track][0];
>>> $flip=$six0[$track][1];
>>>
>>> $max=count($six0);
>>>
>>> $match=0;
>>>
>>> for ($item=0;$item<=$max;$item++){
>>> if ($flip==$six0[$item]['0'])
>>>   {if ($six0[$item][2]=$six0[$track][2])
>>
>> There's no need to assign something to itself just to test it.  The
>> test:
>>
> 
> If you'd bother to comprehend what is happening, it is not assigning
> itself.
> $item is the value derived from the loop.
> $track is the fixed valued assigned at the time of $_GET.
> so if $item and $track are equal then the statement is true 

No.  The _expression_ evaluates to true, if $six[0][$track][2] evaluates
to true.  *Please*, note the difference between assignment and comparison.

>                                                              and the result
> assigns the value to $match and that is what is used to display the proper
> item.
> 
> If $track=1 and $item=101 and the pairs match in value, then $match gets
> the number to use.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#11868 — Re: solved

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-11-19 18:15 +0000
SubjectRe: solved
Message-ID<0.f1a112cfd04d33c5105c.20131119181556GMT.8738msntpf.fsf@bsb.me.uk>
In reply to#11866
richard <noreply@example.com> writes:

> On Tue, 19 Nov 2013 13:50:02 +0000, Ben Bacarisse wrote:
>
>> richard <noreply@example.com> writes:
>> 
>>> <?php
>>>
>>> $track=$_GET['item'];
>>>
>>>
>>> $asong=$six0[$track][0];
>>> $flip=$six0[$track][1];
>>>
>>> $max=count($six0);
>>>
>>> $match=0;
>>>
>>> for ($item=0;$item<=$max;$item++){
>>> if ($flip==$six0[$item]['0'])
>>>   {if ($six0[$item][2]=$six0[$track][2])
>> 
>> There's no need to assign something to itself just to test it.  The
>> test:
>
> If you'd bother to comprehend what is happening, it is not assigning
> itself.

Clam down.  I miss-read the line, it's not a question of not bothering.

> $item is the value derived from the loop.
> $track is the fixed valued assigned at the time of $_GET.
> so if $item and $track are equal then the statement is true and the result
> assigns the value to $match and that is what is used to display the proper
> item.

No, that's not what happens.  The condition is true if and only if
$six0[$track][2] is considered to be true (i.e. not null, false, 0, 0.0,
"", "0", array() or an empty object).

As a side effect, one or more elements of $six0 have their [2] component
set to $six0[$track][2] depending on exactly what data there is in the
array.

Two other points: (1) you access outside the array but running the loop up
to and including $max, and (2) using '0' when you mean 0 is confusing.
It works, but it's not as clear as it should be.

> If $track=1 and $item=101 and the pairs match in value, then $match gets
> the number to use.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#11865 — Re: solved

FromArno Welzel <usenet@arnowelzel.de>
Date2013-11-19 17:43 +0100
SubjectRe: solved
Message-ID<528B952D.9090500@arnowelzel.de>
In reply to#11848
Am 19.11.2013 03:45, schrieb richard:
> <?php
> 
> $track=$_GET['item'];
> 
> 
> $asong=$six0[$track][0];
> $flip=$six0[$track][1];
> 
> $max=count($six0);
> 
> $match=0;
> 
> for ($item=0;$item<=$max;$item++){
> if ($flip==$six0[$item]['0'])
>   {if ($six0[$item][2]=$six0[$track][2])
>    {$match=$item;}}
> }

PLEASE format your code properly!

for($item=0; $item <= $max; $item++)
{
  if($flip == $six0[$item]['0'])
  {
    if($six0[$item][2] = $six0[$track][2])
    {
      $match = $item;
    }
  }
}

And why this?

if($six0[$item][2] = $six0[$track][2])

Please note: "=" is NOT the same as "=="!

If you want to COMPARE $six0[$item][2] and $six0[$track][2] you MUST write:

if($six0[$item][2] == $six0[$track][2])



-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

[toc] | [prev] | [next] | [standalone]


#11870 — Re: solved

Fromrichard <noreply@example.com>
Date2013-11-19 14:41 -0500
SubjectRe: solved
Message-ID<e0zdmv9q27si.s1q3n4mv1gr4.dlg@40tude.net>
In reply to#11865
On Tue, 19 Nov 2013 17:43:25 +0100, Arno Welzel wrote:

> Am 19.11.2013 03:45, schrieb richard:
>> <?php
>> 
>> $track=$_GET['item'];
>> 
>> 
>> $asong=$six0[$track][0];
>> $flip=$six0[$track][1];
>> 
>> $max=count($six0);
>> 
>> $match=0;
>> 
>> for ($item=0;$item<=$max;$item++){
>> if ($flip==$six0[$item]['0'])
>>   {if ($six0[$item][2]=$six0[$track][2])
>>    {$match=$item;}}
>> }
> 
> PLEASE format your code properly!
> 
> for($item=0; $item <= $max; $item++)
> {
>   if($flip == $six0[$item]['0'])
>   {
>     if($six0[$item][2] = $six0[$track][2])
>     {
>       $match = $item;
>     }
>   }
> }
> 
> And why this?
> 
> if($six0[$item][2] = $six0[$track][2])
> 
> Please note: "=" is NOT the same as "=="!
> 
> If you want to COMPARE $six0[$item][2] and $six0[$track][2] you MUST write:
> 
> if($six0[$item][2] == $six0[$track][2])

The script works if it were on one line or 100 lines.

You've never seen a page where the source code was 10,000 characters long
all on one single line?

[toc] | [prev] | [next] | [standalone]


#11871 — Re: solved

From"Beauregard T. Shagnasty" <a.nony.mous@example.invalid>
Date2013-11-19 19:52 +0000
SubjectRe: solved
Message-ID<l6gfh2$cif$1@dont-email.me>
In reply to#11870
richard the sto0pid wrote:

> The script works if it were on one line or 100 lines.
> 
> You've never seen a page where the source code was 10,000 characters
> long all on one single line?

Of course we have. However, they were not *written* that way. They were 
only compressed into that hopelessly unreadable jumble after, and _only_ 
after they were fully debugged and completely tested for operation. *Then* 
they were compressed. And that's only what you see on the web site; the 
developer's source remains well-spaced and indented.

You can't do that. "Debug" is not in your vocabulary.

-- 
   -bts
   - = != ==

[toc] | [prev] | [next] | [standalone]


#11879 — Re: solved

FromArno Welzel <usenet@arnowelzel.de>
Date2013-11-20 16:02 +0100
SubjectRe: solved
Message-ID<528CCF19.6000204@arnowelzel.de>
In reply to#11870
Am 19.11.2013 20:41, schrieb richard:
> On Tue, 19 Nov 2013 17:43:25 +0100, Arno Welzel wrote:
> 
>> Am 19.11.2013 03:45, schrieb richard:
>>> <?php
>>>
>>> $track=$_GET['item'];
>>>
>>>
>>> $asong=$six0[$track][0];
>>> $flip=$six0[$track][1];
>>>
>>> $max=count($six0);
>>>
>>> $match=0;
>>>
>>> for ($item=0;$item<=$max;$item++){
>>> if ($flip==$six0[$item]['0'])
>>>   {if ($six0[$item][2]=$six0[$track][2])
>>>    {$match=$item;}}
>>> }
>>
>> PLEASE format your code properly!
>>
>> for($item=0; $item <= $max; $item++)
>> {
>>   if($flip == $six0[$item]['0'])
>>   {
>>     if($six0[$item][2] = $six0[$track][2])
>>     {
>>       $match = $item;
>>     }
>>   }
>> }
>>
>> And why this?
>>
>> if($six0[$item][2] = $six0[$track][2])
>>
>> Please note: "=" is NOT the same as "=="!
>>
>> If you want to COMPARE $six0[$item][2] and $six0[$track][2] you MUST write:
>>
>> if($six0[$item][2] == $six0[$track][2])
> 
> The script works if it were on one line or 100 lines.

READ what I wrote. I said nothing about the question, if your code works
or not - but I doubt, that you really *know* what the difference is between:

if($six0[$item][2] = $six0[$track][2])

and

if($six0[$item][2] == $six0[$track][2])

Do you? Can you explain, why your code uses the assignement and not the
comparison?

Some how it feels if I already explained this a dozen times and I just
forgot that...

> You've never seen a page where the source code was 10,000 characters long
> all on one single line?

I did. And you don't see any difference in readability above in your
version and my formatted version?

Also see here:

<http://arnowelzel.de/wiki/lib/exe/js.php>

But this does not mean, that such code is *readable* nor that I
recommend to write code this way.

In this special case (<http://arnowelzel.de/wiki/lib/exe/js.php>)  it is
a "compressed" JavaScript to save bandwidth and lower the number of HTTP
requests needed. But this is constructed dynamically by js.php which
takes the local JavaScript files and creates a big "compressed" version
of them in one single block.

But for scripts which remains on the server and will never be
transmitted to the client it should be *readable* for *humans*.


-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.php


csiph-web