FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » searching an array
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
searching an array [message #183740] Mon, 18 November 2013 03:37 Go to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
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")
)
Re: searching an array [message #183743 is a reply to message #183740] Mon, 18 November 2013 04:57 Go to previous messageGo to next message
Richard Yates is currently offline  Richard Yates
Messages: 86
Registered: September 2013
Karma: 0
Member
On Sun, 17 Nov 2013 22:37:44 -0500, richard <noreply(at)example(dot)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.
Re: searching an array [message #183746 is a reply to message #183743] Mon, 18 November 2013 05:28 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
On Sun, 17 Nov 2013 20:57:36 -0800, Richard Yates wrote:

> On Sun, 17 Nov 2013 22:37:44 -0500, richard <noreply(at)example(dot)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 =.
Re: searching an array [message #183749 is a reply to message #183740] Mon, 18 November 2013 11:27 Go to previous messageGo to next message
David Robley is currently offline  David Robley
Messages: 23
Registered: March 2013
Karma: 0
Junior Member
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.
Re: searching an array [message #183767 is a reply to message #183749] Mon, 18 November 2013 16:38 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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(at)attglobal(dot)net
==================
Re: searching an array [message #183775 is a reply to message #183740] Mon, 18 November 2013 18:23 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
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(at)gmail(dot)com
Re: searching an array [message #183776 is a reply to message #183767] Mon, 18 November 2013 18:24 Go to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
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(at)gmail(dot)com
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: file size
Next Topic: array search part 2
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Dec 19 15:13:13 GMT 2024

Total time taken to generate the page: 0.03171 seconds