Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
You can’t perform that action at this time.