Пример #1
0
 /**
  * Convert an array to a string. 
  *
  * PHP API Extension
  * 
  * Example
  * <code>
  * $arr = array('A', 'B', 'indC' => 'C', array('D', 'E'), 'indF'=>'F');
  * echo array_to_string($arr);
  * </code>
  * Output:
  * <code>
  * A,B,indC:C,(D,E),indF:F
  * </code>
  *
  * @access public
  * @static
  * @param array $array
  * @param string $hashsep A character to be used as a hash key and val seperator
  * @param string $elemsep A character to be used as a elememt separator
  * @param string $openarray A character to be used as an open bracket of an array
  * @param string $closearray A character to be used as a close bracket of an array
  * @param boolean $encode Performe encode for key/val or not
  *    Note: encoding is usually necessary especially when you want 
  *    to use delimiter characters in keys and values
  * @return string
  * @see string_to_array
  * @version $Id: v 1.3 2008-07-15 11:14:46 sonots $
  */
 function array_to_string($array, $hashsep = ':', $elemsep = ',', $openarray = '(', $closearray = ')', $encode = true)
 {
     $string = "";
     $delims = $hashsep . $elemsep . $openarray . $closearray;
     foreach ($array as $key => $value) {
         if (is_array($value)) {
             $value = sonots::array_to_string($value, $hashsep, $elemsep, $openarray, $closearray, $encode);
             $value = $openarray . $value . $closearray;
         } else {
             $value = $encode ? sonots::urlencode($value, $delims) : $value;
         }
         if (is_int($key)) {
             $string .= $elemsep . $value;
         } else {
             $key = $encode ? sonots::urlencode($key, $delims) : $key;
             $string .= $elemsep . $key . $hashsep . $value;
         }
     }
     $string = substr($string, 1);
     return $string;
 }