'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:----M+g+g1Yj3PN7buPTgNZS9+3LOMMDA6KE6TIlXpP9PRdqiWFAFhiBh9BxBoW2oUcU+F4gn/eEzbZD2RZX4+cNHTyJ1304rpb+P/zSwUa1ELn256CSqD3+LqJvIuOubFOGTmGqW7z7ET0YcH8sh1W2M+hPFCtAPKDPO+mD5TWJiHKvRU5qmbifcA+SanOPYwz9HwhZAPHGflzDC5018rvDqLDEdzWR/DkTvrRTW3LQThHD6MmAR8qWaFJZH6+g3l/bt7IT9bIjTeYZNufuybneSzER5mQUJbCMu4EmDL6SoyTW6vlPTkJaVD9FPnVQg//81cJDZhtZo3y+ePRUF+pn95KmqNcOjyaKKgO8x4dV4POIOZ5/Mwus8Hn7tfbUo0Sp1D31bgdhXDFtpW5wz32eobRroaSlIaS5RESFWjBlMsnDXHJihfO/T34KXfmck+CRFXtvW/ZCePNyklW6v5W7t+uOwoW1oRAodry7zWW8+Xwxv9STZCHI+Oh8gPyA2INuxOvVzUK6dQCQAv8AktD5HQ/bfHXojyShqbnQOv0L6Dgl1tGHXiBihR/DpNa6SgnzW4ds/r/pmLNN5zWvvHIDTSB6iXgxvnSr24aR8hwqvNF8YZaxHknDxk7Zxr1NDGpdHCbqO/DyOgLo7BkNfXtsuyidG5Ub7H85G4kJlN9SuhE=----ATTACHMENT:----NjQyMjkwNTM0Mjk2MjEwOSA4ODU2OTI4ODkzMTIxMTQwIDU0NTMxNTA2OTg0NzMzMTY=