Ejemplo n.º 1
0
 public function testStringCSV()
 {
     $input = 'a,b,c,d,four,e,0,1,2,3,[NULL],asd;asd|asd"asd\'asd[asd]asd\\asd';
     $result = Re::stringCSV($input);
     $this->assertEquals($result, $input);
     $input = array('a', 'b', 'c', 'd' => 'four', 'e' => 5, 'f' => null, 'g' => false, 'h' => true, 'i' => '');
     $expect = 'a,b,c,four,5,,,1,';
     $result = Re::stringCSV($input);
     $this->assertEquals($result, $expect);
     $expect = 'a,b,c,four,5,1';
     $result = Re::stringCSV(Re::cleanArray($input));
     $this->assertEquals($result, $expect);
 }
Ejemplo n.º 2
0
 /**
  * Returns a string, derived from whatever the input was.
  * if the input was an array, it implode with ','
  *
  * @param mixed $input
  * @return array $inputAsArray
  */
 static function asStringCSV($input)
 {
     return Re::stringCSV($input);
 }
Ejemplo n.º 3
0
 /**
  * Returns a string, derived from whatever the input was.
  * if the input was an array, it implode with ','
  * @param mixed $input
  * @return array $inputAsArray
  */
 public static function stringCSV($input)
 {
     if ($input === 0 || $input === '0') {
         return 0;
     }
     if (empty($input)) {
         return '';
     }
     if (is_object($input)) {
         $input = get_object_vars($input);
     }
     if (is_array($input)) {
         foreach (array_keys($input) as $key) {
             if (is_array($input[$key])) {
                 $input[$key] = Re::stringCSV($input[$key]);
             }
         }
         $input = implode(',', $input);
     }
     return strval($input);
 }