Skip to content

Instantly share code, notes, and snippets.

@tarunama
Last active August 29, 2015 14:01
Show Gist options
  • Save tarunama/11555235 to your computer and use it in GitHub Desktop.
Save tarunama/11555235 to your computer and use it in GitHub Desktop.
[PHP]unset構文と処理速度 ref: http://qiita.com/tarunama/items/3385acb60f20c055d048
<?PHP
$content = fopen($argv[1], "r");
while (($line = fgets($content)) !== false) {
$ary = preg_split("/[\s]/", $line);
$str = $ary[1];
$pattern = preg_split("/[\\+\-]/", $ary[1]);
foreach (str_split($pattern[0]) as $val) {
$left[] = $val;
}
foreach (str_split($pattern[1]) as $val) {
$right[] = $val;
}
$leftnumber = substr($ary[0], 0, count($left));
$rightnumber = substr($ary[0], count($left));
if (strstr($ary[1], "+")) {
echo $leftnumber + $rightnumber . PHP_EOL;
} elseif (strstr($ary[1], "-")) {
echo $leftnumber - $rightnumber . PHP_EOL;
}
unset($left, $right);
}
fclose($content);
<?PHP
$content = fopen($argv[1], "r");
while (($line = fgets($content)) !== false) {
$ary = preg_split("/[\s]/", $line);
$str = $ary[1];
$pattern = preg_split("/[\\+\-]/", $ary[1]);
foreach (str_split($pattern[0]) as $val) {
$left[] = $val;
}
foreach (str_split($pattern[1]) as $val) {
$right[] = $val;
}
$leftnumber = substr($ary[0], 0, count($left));
$rightnumber = substr($ary[0], count($left));
if (strstr($ary[1], "+")) {
echo $leftnumber + $rightnumber . PHP_EOL;
} elseif (strstr($ary[1], "-")) {
echo $leftnumber - $rightnumber . PHP_EOL;
}
unset($left, $right, $rightnumber, $leftnumber);
}
fclose($content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment