sublimeText を使用して古い配列を新しい php 構文に変換する方法 (正規表現、スニペット、プラグインなど) を探しています。
// Old synthax
$var = array(
'foo' => 'bar'
);
// New synthax
$var = [
'foo' => 'bar'
];
誰かがアイデアを持っていますか?
sublimeText を使用して古い配列を新しい php 構文に変換する方法 (正規表現、スニペット、プラグインなど) を探しています。
// Old synthax
$var = array(
'foo' => 'bar'
);
// New synthax
$var = [
'foo' => 'bar'
];
誰かがアイデアを持っていますか?
仕事を完璧に行うスクリプトを見つけました!
https://github.com/thomasbachem/php-short-array-syntax-converter
少し遅いかもしれませんが、自分で作成しました。きれいではないかもしれませんが、それは私が望む仕事をします. タブが苦手な方は、インデント機能の \t を 2 ~ 4 スペースに変更してください。
function loopArray(array $array, $loopcount = 0) {
$returnString = ($loopcount == 0) ? "[\n" : "";
$tabKey = indent($loopcount + 2);
$tabValue = indent($loopcount + 3);
$lastKey = array_key_last($array);
foreach ($array as $key => $value) {
$totalChildren = count($array[$key]);
$returnString .= $tabKey . '"' . $key . '" => ';
if ($totalChildren == 0) $returnString .= '[]';
if ($totalChildren > 0 && is_array($array[$key])) $returnString .= '[' . "\n";
if (is_array($value)) {
$returnString .= loopArray($value, $loopcount + 1);
} else {
if ($totalChildren == 1) $returnString .= '"' . $value . '"';
if ($totalChildren > 1) $returnString .= $tabValue . '"' . $value . '"' . ",\n";
}
$returnString .= ($lastKey == $key) ? "\n" . indent($loopcount+1) . "]" : ",\n";
}
return $returnString;
}
function indent($amount) {
return str_repeat("\t", $amount);
}
/** use function below only prior to php 7.3 */
function array_key_last(array $array) {
$key = NULL;
if ( is_array( $array ) ) {
end( $array );
$key = key( $array );
}
return $key;
}