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

Home » Imported messages » comp.lang.php » Using count() as an array index
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Using count() as an array index [message #178442 is a reply to message #178440] Mon, 18 June 2012 17:38 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 6/18/2012 10:46 AM, Martin Leese wrote:
> Jerry Stuckle wrote:
>> On 6/17/2012 9:57 AM, Martin Leese wrote:
>>> Jerry Stuckle wrote:
>>> ...
>>>> Be aware, though - the typical array in PHP starts counting at 0, not
>>>> 1. So an array of 3 elements would be numbered 0, 1 and 2. In this
>>>> case, an element with an index of 3 (count($anArray)) is not set (and
>>>> will give a warning if you try to use it).
>>>>
>>>> You need to get used to this idea; it's used throughout PHP.
>>>
>>> The test code I posted was taken from my
>>> application in which I deliberately start my
>>> array with [1]. This is because the array
>>> holds numbered sections of an FAQ, and it
>>> makes more sense to have Section 1 in array
>>> element [1], etc.
>>
>> Actually, I think it's a bad way to do things. What happens if you
>> want to add a new section - or delete one? You'll have to change your
>> code, which should never be the case.
>>
>> A better way is to hold the information in a database.
>
> No, I will not need to change my code. I
> am using an array as a replacement for a
> database. Here is a snippet of my file
> faqData.php to give you the idea:
>
> // Set data to identify Web page, and set prev and next anchors
> // Note that the first set must have index explicitly set to [1]
> $tempIndex = 1;
> $dataHref[$tempIndex] = "Ambisonic/faq_section01.html";
> $dataAnchorText[$tempIndex] = "1. Where can I get this FAQ?";
> $dataCompleteText[$tempIndex] = "1. <a href=\"#SECTION1\">Where can I
> get this FAQ?</a>";
> $dataSplitText[$tempIndex] = "1. <a rel=\"section\"
> href=\"$dataHref[$tempIndex]\">Where can I get this FAQ?</a>";
>
> $tempIndex++;
> $dataHref[$tempIndex] = "Ambisonic/faq_section02.html";
> $dataAnchorText[$tempIndex] = "2. Corrections to the FAQ";
> $dataCompleteText[$tempIndex] = "2. <a href=\"#SECTION2\">Corrections to
> the FAQ</a>";
> $dataSplitText[$tempIndex] = "2. <a rel=\"section\"
> href=\"$dataHref[$tempIndex]\">Corrections to the FAQ</a>";
>

Yes, which means if you need to change your FAQs you need to change this
code.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[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
Previous Topic: runkit
Next Topic: PHP mysql_excape but need to search for those items
Goto Forum:
  

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

Current Time: Fri Nov 22 09:21:07 GMT 2024

Total time taken to generate the page: 0.05199 seconds