How to force an associative array

[email protected] (John Iliffe)
Newsgroups php.general
Message-ID <[email protected]>
I have an application where the members (by name) of an associative array are
not known until run time.  I have been unable to force the member names to the
correct name, what I get is a single addition to the array with the name 0,
indicating that this is being created with the elements numbered. All added
members of the array disappear except the last one added.

$_head_array = array("start"=>"start");

if (($_pos = stripos($_the_header,$_head_reqd[$_k])) !== false)
        {
         if ($_pos < 3)
           {
            $_name = substr($_head_req[$_k],0,-1);      // knock off ':'
            $_head_array[$_name] = $_the_header;      
           }
        }

... etc

What this is doing is iterating through $_head_reqd (a list of header names) to
find out if $_the_header is one of these.  If so, it is added to the associative
array $_head_array.  I set up $_head_array with a first element "start"=>"start"
to force (as I thought) an associative array.

What results (as displayed by print_r):

-----------selected headers--------
Array
(
    [start] => start
    [0] => Subject: 876543
)
----------end of selected headers-----

Several hits preceding "Subject" are not recorded even though they were selected
initially, and the last line SHOULD read "[Subject] => Subject: 876543"

How can I force the proper element names?

Thanks in advance.

John
======
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.