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 #183806 is a reply to message #183796] Wed, 20 November 2013 15:02 Go to previous message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma:
Senior Member
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
[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: Fri Nov 22 03:12:24 GMT 2024

Total time taken to generate the page: 0.04502 seconds