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

Home » Imported messages » comp.lang.php » array search part 2
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: solved [message #183785 is a reply to message #183780] Tue, 19 November 2013 13:50 Go to previous messageGo to previous message
Ben Bacarisse is currently offline  Ben Bacarisse
Messages: 82
Registered: November 2013
Karma:
Member
richard <noreply(at)example(dot)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 ($six0[$item][2]) ...

is probably what you want, though the assignment will create
$six0[$item][2] if it does not already exist, so the two are not exactly
the same.

> {$match=$item;}}
> }
>
> http://mroldies.net/list/decade60.html
>
> The for loop searches through the array for a match first based on name.
> Then further matches by label number.
> [0]=charted name
> [1]=flipside
> [2]=label

You can make the code more self-documenting by using defined constants
for these indexes:

define('FLIPSIDE', 1);
define('LABEL', 2);
...
if ($six0[$item][LABEL]) ...

or by using string indexes directly (e.g. if ($six0[$item]['label']) ...).

--
Ben.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: searching an array
Next Topic: Perform maths based on a number in a text file
Goto Forum:
  

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

Current Time: Sat Nov 30 09:15:26 GMT 2024

Total time taken to generate the page: 0.04571 seconds