Last active
August 29, 2015 14:01
-
-
Save tarunama/11555235 to your computer and use it in GitHub Desktop.
[PHP]unset構文と処理速度 ref: http://qiita.com/tarunama/items/3385acb60f20c055d048
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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