AE117 Posted November 23, 2009 Share Posted November 23, 2009 implode(', ', $value); with that function in php is there a way to have it show the key instead of the value. I havnt found anything about that and I am wondering if anyone else has. I have an array and in the array I can echo the key and then the value, the reason I put the implode is becuase it will show it as such 1, 2, 3, 4 etc but I want the keys not the values to show. Link to comment https://forums.phpfreaks.com/topic/182606-implode-and-show-key/ Share on other sites More sharing options...
iversonm Posted November 23, 2009 Share Posted November 23, 2009 by using implode it will no longer be an array and it wont have keys for each value. It'll be a long string. explode will turn it into an array. Link to comment https://forums.phpfreaks.com/topic/182606-implode-and-show-key/#findComment-963763 Share on other sites More sharing options...
AE117 Posted November 23, 2009 Author Share Posted November 23, 2009 I seem to be making a habit of solving my own problems but I do hope that everyone else that comes across my problems can find it here the easy way instead of my way. to implode and array to show the keys only function implode_with_key($assoc,$inglue='>',$outglue=', '){ $return=''; foreach($assoc as $tk=>$tv){ $return.=$outglue.$tk; } return substr($return,strlen($outglue)); } nothing in side that needs to be changed. to echo <?php echo implode_with_key($yourarray); ?> Link to comment https://forums.phpfreaks.com/topic/182606-implode-and-show-key/#findComment-963765 Share on other sites More sharing options...
AE117 Posted November 23, 2009 Author Share Posted November 23, 2009 by using implode it will no longer be an array and it wont have keys for each value. It'll be a long string. explode will turn it into an array. Yes that was to my understanding and apparently there are creative ways to get around such a deli ma. Link to comment https://forums.phpfreaks.com/topic/182606-implode-and-show-key/#findComment-963766 Share on other sites More sharing options...
iversonm Posted November 23, 2009 Share Posted November 23, 2009 I find myself doing that to all the time. haha nice work. topic solved? Link to comment https://forums.phpfreaks.com/topic/182606-implode-and-show-key/#findComment-963767 Share on other sites More sharing options...
AE117 Posted November 23, 2009 Author Share Posted November 23, 2009 Yes it is I thought there was a topic solved button on this forum but I can seem to locate it. I have been staring at my monitors for far too long. Link to comment https://forums.phpfreaks.com/topic/182606-implode-and-show-key/#findComment-963769 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.