[SOLVED] Problem with array_keys

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mahesh
Forum Newbie
Posts: 7
Joined: Sat Apr 10, 2004 4:48 am
Location: Coimbatore, India
Contact:

Problem with array_keys

Post by Mahesh »

Hi,

I am parsing an xml file. I have stored the attributes of the XML file in an array. I am using array_keys to return key values from the array. This function returns only unique values. I have several repeatations of a key in the array, but array_keys fetches only unique values. Is there some other way I can get all the key values?

Please Help

Thanks
Mahesh
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

note how this works:

Code: Select all

<?php

	$test = array('test'=>1,'test'=>2,'test'=>3);
	
	print_r($test);
	
	print_r(array_keys($test));

?>
outputs

Code: Select all

Array
(
    &#1111;test] =&gt; 3
)
Array
(
    &#1111;0] =&gt; test
)
Mahesh
Forum Newbie
Posts: 7
Joined: Sat Apr 10, 2004 4:48 am
Location: Coimbatore, India
Contact:

Problem with list

Post by Mahesh »

Sorry, the problem is becuase I had used a list to hold values which does not allow duplicate values. How can I enter duplicate values to list?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you could check for the existance of the key you are attempting to enter, and concatenate with an existing one..
Mahesh
Forum Newbie
Posts: 7
Joined: Sat Apr 10, 2004 4:48 am
Location: Coimbatore, India
Contact:

Post by Mahesh »

Thank You for the suggestions. I managed it to achiveve it through another program :)
Post Reply