Assoc Array to String & String to Assoc Array

pradeep's Avatar author of Assoc Array to String & String to Assoc Array
This is an article on Assoc Array to String & String to Assoc Array in PHP.
I like coding PHP, in Perl we can change an associative array to a list then to a string. In case if we wish to do the same in PHP, we need to write some user functions for that purpose.
Here are two functions which will convert Array to String and vice-versa.

PHP Code:
//array to string
 
function arraytostr ($array=array()) {
 
      
$length 0;
      
$foreach ($array as $key => $value) {
           
$keystring .= "$key ";
           
$valuestring .= "$value ";
           
$length++;
      }
         
      return array(
$length,$keystring,$valuestring);
 }
 
 
//sting to array    
 
function strtoarray ($length="",$keystring="",$valuestring="") {
           
$keys explode(" ",$keystring);
           
$values explode(" ",$valuestring);
           for (
$i=0$i $length$i++) {
         
$key $keys[$i];
         
$newarray[$key] = $values[$i];
           }
         
           return 
$newarray;
 }