Jump to content

implode and show key


AE117

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.