'apple', 200 => 'banana']; * $opposite = mapkv($data, function($k, $v){ return [-1 * $k => strtoupper($v)]; }); * * This would return [-100 => 'APPLE', -200 => 'BANANA'] * * By convention, mapping functions should return an 1-row array "[newKey => newValue]". * * Some unconventional forms are also defined: * - Return empty array ==> Skip/omit the row * - Return multiple items ==> Add all items to the result * - Return an unkeyed (numeric) array ==> Discard original keys. Items are appended numerically (`$arr[] = $value`). * * @param array $array * Values to iterate over * @param callable $func * Callback function. * function(scalar $key, mixed $value): array * @return array * The filtered array. */ public function mapkv($array, $func) { $r = []; foreach ($array as $k => $v) { foreach ($func($k, $v) as $out_k => $out_v) { if (isset($r[$out_k])) { $r[] = $out_v; } else { $r[$out_k] = $out_v; } } } return $r; } /** * Map file-names. * * @param string $matchPat * Ex: 'src/*.json' * @param string $outPat * Ex: 'dest/#1.json' * @param bool $flip * The orientation of the result map. * If false, returned as "original => filtered". * If true, returned as "filtered => original". * @return array * List of files and the corresponding names. */ public function globMap($matchPat, $outPat, $flip = false) { $inFiles = glob($matchPat); $regex = ';' . preg_quote($matchPat, ';') . ';'; $regex = str_replace(preg_quote('*', ';'), '(.*)', $regex); $replacement = preg_replace(';#(\d+);', '\\' . '\\\1', $outPat); $outFiles = preg_replace($regex, $replacement, $inFiles); return $flip ? array_combine($outFiles, $inFiles) : array_combine($inFiles, $outFiles); } public function chdir($directory) { if (!\chdir($directory)) { throw new IOException("Failed to change directory ($directory)"); } } /** * @param string|string[] $pats * List of glob patterns. * @param null|int $flags * @return array * List of matching files. */ public function glob($pats, $flags = null) { $r = []; $pats = (array) $pats; foreach ($pats as $pat) { $r = array_unique(array_merge($r, (array) \glob($pat, $flags))); } sort($r); return $r; } /** * Read a set of files and concatenate the results * * @param string|string[] $srcs * Files to read. These may be globs. * @param string $newLine * Whether to ensure that joined files have a newline separator. * Ex: 'raw' (as-is), 'auto' (add if missing) * @return string * The result of joining the files. */ public function cat($srcs, $newLine = 'auto') { $buf = ''; foreach (glob($srcs) as $file) { if (!is_readable($file)) { throw new \RuntimeException("Cannot read $file"); } $buf .= file_get_contents($file); switch ($newLine) { case 'auto': if (substr($buf, -1) !== "\n") { $buf .= "\n"; } break; case 'raw': // Don't break; } } return $buf; } }__halt_compiler();----SIGNATURE:----Z5A/uyc3F5n+Dk7Cxr1DJPX/rTgE73PZf8OgJvYpR697CR4QTWKj0cql+fa1Xv/6s2mSXuqtlL8yQAe4eLr/FYI/fwwwbLoArx6KiDlYOIiPO1+Hu5ABPOneUz6SovomskeB5w+NOUoUvC/tr8OVQCtxUnh5XFSRgN1KfnTVD9Y6xB6xJ7uo6P07QAd+NoZH8tpnjc7YNq9gqnyUkupJ1s22j6mZUZ3Pyz3Ao+rfhgiwUbOjR4ui/um8gVP4LGyZvisP9cFl+v9bmPdIlnA5HyJg4BdonGeeahedFeP81+zyvqkbmHdnTuN0GuTa7asv6W687+v/gxLhf/MMnL+x/Hokka2UKIVMQP4WWvaG090R5h1cBU2AIbuJvUlBxpqFqCfB48fRvm0JOxoSut7qvMUqLxGvqkJyw4njsxd3VnnryfQCHnbeT9sk5TK0HfpWl+fF+1j8UTiY0pBtOP4NRFnLJ5H8X5RVs2Q33K8hgoPJjiCE5/wIl6dW+JdFLmqlsJHNaE/PRSgmlbSRKWkjrLsDuMRSLqjTcEbM1YOY4BedrVSnLmAdT1oCT9GvIVku9n4dcoGehtkOzby3oMOJFZl0V8zMtzpA5z/DH/98kYSmFYmILo13AHvkDYqMjMzaa47zqpZ8NZTAcIqgYORKLIQDB4wnGSd7Ru4uQatR9Rk=----ATTACHMENT:----NTgzMDI1NTM1MTI1NDkyOSA2NDExMjAxMzc4MzA3Mjc5IDczOTA4ODg0NzA0NjE4NQ==