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


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

searching an array

Started byrichard <noreply@example.com>
First post2013-11-17 22:37 -0500
Last post2013-11-18 18:23 +0000
Articles 7 — 5 participants

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


Contents

  searching an array richard <noreply@example.com> - 2013-11-17 22:37 -0500
    Re: searching an array Richard Yates <richard@yatesguitar.com> - 2013-11-17 20:57 -0800
      Re: searching an array richard <noreply@example.com> - 2013-11-18 00:28 -0500
    Re: searching an array David Robley <me@home.invalid> - 2013-11-18 21:57 +1030
      Re: searching an array Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-18 11:38 -0500
        Re: searching an array Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-18 18:24 +0000
    Re: searching an array Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-18 18:23 +0000

#11813 — searching an array

Fromrichard <noreply@example.com>
Date2013-11-17 22:37 -0500
Subjectsearching an array
Message-ID<1r19n2u8ujc0e$.kh04fdyfhu79$.dlg@40tude.net>
I am now attempting to set up a display using a simple table.
row 1 is headers.
row 2 is for the main track title.
row 3 is for the flipside.

http://mroldies.net/list/decade60.html

Many times the flipside was also charted.
So I need to know what the corresponding number is for the flipside in
order to show that information.

from the "manual" I am using this:

$flip=$six0[$track][1];

$flip2=array_search($flip,$six0);

if ($flip2=null){echo "does not exist";}

How do I properly code it so that when a match is not found?
Neither null or "" seems to work.

$six0=array(
1 => array("The Theme From \"A Summer Place\"","Go-Go-Po-Go","Columbia
4-41490","Percy Faith","Max Steiner","21","1","1/11/1960","1"),
2 => array("Are You Lonesome To-Night?","I Gotta Know*","RCA Victor
47-7810","Elvis Presley","Roy Turk Lou Handman","16","1","11/14/1960","2"),
3 => array("It's Now Or Never","A Mess Of Blues*","RCA Victor
47-7777","Elvis Presley","Aaron Schroeder Wally
Gold","20","1","7/18/1960","3")
)

[toc] | [next] | [standalone]


#11815

FromRichard Yates <richard@yatesguitar.com>
Date2013-11-17 20:57 -0800
Message-ID<s97j89p9u8aebf6ljstmc1p5kllq4ouvdf@4ax.com>
In reply to#11813
On Sun, 17 Nov 2013 22:37:44 -0500, richard <noreply@example.com>
wrote:

>I am now attempting to set up a display using a simple table.
>row 1 is headers.
>row 2 is for the main track title.
>row 3 is for the flipside.
>
>http://mroldies.net/list/decade60.html
>
>Many times the flipside was also charted.
>So I need to know what the corresponding number is for the flipside in
>order to show that information.
>
>from the "manual" I am using this:
>
>$flip=$six0[$track][1];
>
>$flip2=array_search($flip,$six0);
>
>if ($flip2=null){echo "does not exist";}
>
>How do I properly code it so that when a match is not found?
>Neither null or "" seems to work.
>
>$six0=array(
>1 => array("The Theme From \"A Summer Place\"","Go-Go-Po-Go","Columbia
>4-41490","Percy Faith","Max Steiner","21","1","1/11/1960","1"),
>2 => array("Are You Lonesome To-Night?","I Gotta Know*","RCA Victor
>47-7810","Elvis Presley","Roy Turk Lou Handman","16","1","11/14/1960","2"),
>3 => array("It's Now Or Never","A Mess Of Blues*","RCA Victor
>47-7777","Elvis Presley","Aaron Schroeder Wally
>Gold","20","1","7/18/1960","3")
>)

Ask yourself: What single type of error have I made repeatedly and has
been pointed out here over and over and over and over? 

If you can answer that then you are equal to the task, although that
is not the same as correcting it.

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


#11816

Fromrichard <noreply@example.com>
Date2013-11-18 00:28 -0500
Message-ID<1tunadj6vppqy$.1hqvjmlh7ggj5$.dlg@40tude.net>
In reply to#11815
On Sun, 17 Nov 2013 20:57:36 -0800, Richard Yates wrote:

> On Sun, 17 Nov 2013 22:37:44 -0500, richard <noreply@example.com>
> wrote:
> 
>>I am now attempting to set up a display using a simple table.
>>row 1 is headers.
>>row 2 is for the main track title.
>>row 3 is for the flipside.
>>
>>http://mroldies.net/list/decade60.html
>>
>>Many times the flipside was also charted.
>>So I need to know what the corresponding number is for the flipside in
>>order to show that information.
>>
>>from the "manual" I am using this:
>>
>>$flip=$six0[$track][1];
>>
>>$flip2=array_search($flip,$six0);
>>
>>if ($flip2=null){echo "does not exist";}
>>
>>How do I properly code it so that when a match is not found?
>>Neither null or "" seems to work.
>>
>>$six0=array(
>>1 => array("The Theme From \"A Summer Place\"","Go-Go-Po-Go","Columbia
>>4-41490","Percy Faith","Max Steiner","21","1","1/11/1960","1"),
>>2 => array("Are You Lonesome To-Night?","I Gotta Know*","RCA Victor
>>47-7810","Elvis Presley","Roy Turk Lou Handman","16","1","11/14/1960","2"),
>>3 => array("It's Now Or Never","A Mess Of Blues*","RCA Victor
>>47-7777","Elvis Presley","Aaron Schroeder Wally
>>Gold","20","1","7/18/1960","3")
>>)
> 
> Ask yourself: What single type of error have I made repeatedly and has
> been pointed out here over and over and over and over? 
> 
> If you can answer that then you are equal to the task, although that
> is not the same as correcting it.

I get the same result if I use == or =.

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


#11819

FromDavid Robley <me@home.invalid>
Date2013-11-18 21:57 +1030
Message-ID<l6ctf3$sgr$1@news.albasani.net>
In reply to#11813
richard wrote:

> I am now attempting to set up a display using a simple table.
> row 1 is headers.
> row 2 is for the main track title.
> row 3 is for the flipside.
> 
> http://mroldies.net/list/decade60.html
> 
> Many times the flipside was also charted.
> So I need to know what the corresponding number is for the flipside in
> order to show that information.
> 
> from the "manual" I am using this:
> 
> $flip=$six0[$track][1];
> 
> $flip2=array_search($flip,$six0);
> 
> if ($flip2=null){echo "does not exist";}
> 
> How do I properly code it so that when a match is not found?
> Neither null or "" seems to work.
> 
> $six0=array(
> 1 => array("The Theme From \"A Summer Place\"","Go-Go-Po-Go","Columbia
> 4-41490","Percy Faith","Max Steiner","21","1","1/11/1960","1"),
> 2 => array("Are You Lonesome To-Night?","I Gotta Know*","RCA Victor
> 47-7810","Elvis Presley","Roy Turk Lou
> Handman","16","1","11/14/1960","2"), 3 => array("It's Now Or Never","A
> Mess Of Blues*","RCA Victor 47-7777","Elvis Presley","Aaron Schroeder
> Wally Gold","20","1","7/18/1960","3")
> )

Other(s) have mentioned the confusion of = and ==.

Seeing you are quoting the "manual" you may wish to refer to it again and 
see what the return value of array_search is if a match is not found; it is 
neither null or "". It might also be useful to review the warning under the 
information on return values.

-- 
Cheers
David Robley

If I had anything witty to say, I wouldn't put it here.

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


#11836

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-11-18 11:38 -0500
Message-ID<l6dfpt$2gc$1@dont-email.me>
In reply to#11819
On 11/18/2013 6:27 AM, David Robley wrote:
> richard wrote:
>
>> I am now attempting to set up a display using a simple table.
>> row 1 is headers.
>> row 2 is for the main track title.
>> row 3 is for the flipside.
>>
>> http://mroldies.net/list/decade60.html
>>
>> Many times the flipside was also charted.
>> So I need to know what the corresponding number is for the flipside in
>> order to show that information.
>>
>> from the "manual" I am using this:
>>
>> $flip=$six0[$track][1];
>>
>> $flip2=array_search($flip,$six0);
>>
>> if ($flip2=null){echo "does not exist";}
>>
>> How do I properly code it so that when a match is not found?
>> Neither null or "" seems to work.
>>
>> $six0=array(
>> 1 => array("The Theme From \"A Summer Place\"","Go-Go-Po-Go","Columbia
>> 4-41490","Percy Faith","Max Steiner","21","1","1/11/1960","1"),
>> 2 => array("Are You Lonesome To-Night?","I Gotta Know*","RCA Victor
>> 47-7810","Elvis Presley","Roy Turk Lou
>> Handman","16","1","11/14/1960","2"), 3 => array("It's Now Or Never","A
>> Mess Of Blues*","RCA Victor 47-7777","Elvis Presley","Aaron Schroeder
>> Wally Gold","20","1","7/18/1960","3")
>> )
>
> Other(s) have mentioned the confusion of = and ==.
>
> Seeing you are quoting the "manual" you may wish to refer to it again and
> see what the return value of array_search is if a match is not found; it is
> neither null or "". It might also be useful to review the warning under the
> information on return values.
>

David,

People have pointed this problem out to Richard about once every two 
months for years.  He never learns.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

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


#11845

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-11-18 18:24 +0000
Message-ID<l6dm10$5ba$4@dont-email.me>
In reply to#11836
On Mon, 18 Nov 2013 11:38:20 -0500, Jerry Stuckle wrote:

> People have pointed this problem out to Richard about once every two
> months for years.  He never learns.

Objection m'lud. I believe it's now decades.

-- 
Denis McMahon, denismfmcmahon@gmail.com

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


#11844

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-11-18 18:23 +0000
Message-ID<l6dlv7$5ba$3@dont-email.me>
In reply to#11813
On Sun, 17 Nov 2013 22:37:44 -0500, richard wrote:

> $flip2=array_search($flip,$six0);
> 
> if ($flip2=null){echo "does not exist";}
> 
> How do I properly code it so that when a match is not found?
> Neither null or "" seems to work.

TL;DR: RTFM!

You read the php manual for the search function which you're using and 
take very careful note of the value returned when the needle item is not 
found in the haystack item. Then you test for that value.

Instead of testing for some random value that enters your head.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [standalone]


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


csiph-web