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 #183794 is a reply to message #183792] Tue, 19 November 2013 18:15 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:

> On Tue, 19 Nov 2013 13:50:02 +0000, Ben Bacarisse wrote:
>
>> 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 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.
[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: Tue Feb 18 17:26:50 GMT 2025

Total time taken to generate the page: 0.04403 seconds