public static function findBy($collection, $property, $value, $comparisonOp = "eq")
 {
     $filtered = static::filterBy($collection, $property, $value, $comparisonOp);
     return \Underscore\Methods\ArraysMethods::first($filtered);
 }
 public static function findBy($collection, $property, $value, $comparisonOp = 'eq')
 {
     $filtered = static::filterBy($collection, $property, $value, $comparisonOp);
     return ArraysMethods::first($filtered);
 }
 /**
  * Get everything but the last $to items
  */
 public static function initial($array, $to = 1)
 {
     $slice = sizeof($array) - $to;
     return ArraysMethods::first($array, $slice);
 }
Exemple #4
0
 /**
  * Converts data to CSV
  *
  * @param  mixed $data The data to convert
  *
  * @return string Converted data
  */
 public static function toCSV($data, $delimiter = ';', $exportHeaders = false)
 {
     $csv = array();
     // Convert objects to arrays
     if (is_object($data)) {
         $data = (array) $data;
     }
     // Don't convert if it's not an array
     if (!is_array($data)) {
         return $data;
     }
     // Fetch headers if requested
     if ($exportHeaders) {
         $headers = array_keys(ArraysMethods::first($data));
         $csv[] = implode($delimiter, $headers);
     }
     // Quote values and create row
     foreach ($data as $header => $row) {
         // If single column
         if (!is_array($row)) {
             $csv[] = '"' . $header . '"' . $delimiter . '"' . $row . '"';
             continue;
         }
         // Else add values
         foreach ($row as $key => $value) {
             $row[$key] = '"' . stripslashes($value) . '"';
         }
         $csv[] = implode($delimiter, $row);
     }
     return implode(PHP_EOL, $csv);
 }