PHPã¨ãããããæ¼ç®ä»£å ¥ç³»ã®æ¼ç®åã®ããã·
PHPã®é¢æ°å®ç¾©ã¯ãããªå¤æ çãªæ¸ãæ¹ãã§ãã - é ãä¸
ã«ãç¶ãã¦ãã¢ã³ãªã¼ããã«ã³ã¼ãã§åå¼·ãããã¨ããã®ããã£ãããã®ã¨ããåå¼·ä¼ã®çºè¡¨ãã¿ã§ãã
ããã¯ãPHPã®Markdownãã¼ãµ ã®å®è£ ãå¯è½ãªéããã®ã¾ã¾ç¶ºéºã«å¤æãã¦JavaScriptã«ç§»æ¤ãããã¨ãã js-markdown-extra ããã£ã¦ããã¨ãã大ããããã¦ä¿®æ£ã«è¦å´ãããã°ã®è©±ããæ¥ã¦ã¾ãã
æ¼ç®ä»£å
¥ã+=
ã¨ã *=
ã¨ãã®ãã¤ãé¢æ°åã®äººä»¥å¤ã¯ãã£ã¨å¸¸ç¨ãã¦ã¾ããããããåé¡ã
<?php $tokens = array("a", "b", "c"); $tokens[0] .= array_shift($tokens); print_r($tokens);
ããããã¨ã©ããªçµæãåºåãããã§ãããããPHPã§ãã
èªèº«ã®å
é ããè¦ç´ ãåãåºãã¦ããããå
é è¦ç´ ã«æåå追å ãããarray_shift()
ã§ã¯ "a"
ãå
é ããåãåºãã㦠$tokens == array("b", "c")
ã«ãªãã¾ããåãåºãããå¤ã¯é
åã®å
é è¦ç´ ã«ãæååã¨ãã¦è¿½å ãããã¦é
åã®å
é è¦ç´ ã«ä»£å
¥ããã¾ããçµæãè¦ã¾ãããã
$ php test.php Array ( [0] => ba [1] => c )
...ã£ã¦æãã¾ããããããã¾ã§ãããã§ããããããªãã§ããã
ã¨ãããPHPã¯... ã¨ãã話ã ã¨æã£ãã大ééããããPHP以å¤ã®è¨èªã®äººãªããééã£ã¦ããã®ã¯ããªãã®ããã°ã©ãã³ã°è½åã§ããã¨ãPHPerã¯ããã§OKã§ãã
JavaScriptã§æ¸ãã¾ããã
var tokens = ["a", "b", "c"]; tokens[0] += tokens.shift(); console.log(tokens);
ãªãã¨ãããçãã¯ããåºã¾ãã
$ node test.js [ 'aa', 'c' ]
ããããã¾ã JavaScript ã¯å¤ãªè¨èªã ãããã...
ããã«Pythonå§å¡é·ããã£ã¦ããã
tokens = ["a", "b", "c"] tokens[0] += tokens.pop(0) print tokens
â
$ python test.js ['aa', 'c']
ãã°ã!! PHPã¡ãããå¤æ°æ±ºã§è² ãã¡ãããå©ãã¦Rubyã¡ããã(å«ãªãã¨è¨ããããã¨ããããã©ãæè¿å«ããããªãã®ããããã®åã)
tokens = ["a", "b", "c"] tokens[0] += tokens.shift p tokens
â
$ ruby test.rb ["aa", "c"]
ãããããã¼ã¼ã¼ã£ãRubyåã¡ããã¾ã§ãPHPã¡ããããããããããã
æ¤è¨¼
ããã¾ãããã¡ããã¨ããã¾ããã¯ããããããã«ãa += b
ã a = a + b
ã¨ç価ã£ã¦ã®ããããã°ãããã§ããããã£ã¨ãJavaScriptã§æ¤è¨¼ããã£ã¦ã¿ã¾ãããã
function equal_and_plus() { var tokens = ["a", "b", "c"]; tokens[0] = tokens[0] + tokens.shift(); console.log(tokens); } function equal_plus_operator() { var tokens = ["a", "b", "c"]; tokens[0] += tokens.shift(); console.log(tokens); } equal_and_plus(); equal_plus_operator();
â
[ 'aa', 'c' ] [ 'aa', 'c' ]
åæ ¼ã§ãããPythonãRubyãããã¨åãã§ããããããPHPã¯ãã£ãã...
<?php function equal_and_plus() { $tokens = array("a", "b", "c"); $tokens[0] = $tokens[0] . array_shift($tokens); ptint_r($tokens); } function equal_plus_operator() { $tokens = array("a", "b", "c"); $tokens[0] .= array_shift($tokens); ptint_r($tokens); } equal_and_plus(); equal_plus_operator();
â
Array ( [0] => aa [1] => c ) Array ( [0] => ba [1] => c )
éãæ¼ç®ãããããã
ãã®ã¨ãããPHPã®å ´åã¯ãå ç®ã¨ä»£å ¥ãã¯ãå ç®ä»£å ¥ãã¨ç価ã§ã¯ãªãã£ãã®ã§ããã¡ãã£ã¨æåã«åããåã«æ³åããçµæã«æ»ã£ã¦ã¿ã¦ãã ããããåãåºãã¦ãâ(å³è¾ºã®å¤æ°ãå¤åãã¦)âãä»£å ¥ãã£ã¦èãã¾ãããããPHPã¯ãã®ã¨ããåãã¾ããã
ã§ãä»ã®è¨èªã§ã¯å®éã«ã¯ããå ç®ä»£å
¥ã¯å ç®ã¨ä»£å
¥ã§ãããã¨ããç価é¢ä¿ãæ»å®ãã¾ãããã®çµæãæåã«è©ä¾¡ãããã®ã¯ tokens[0] = tokens[0] + shift(tokens)
左辺ã®ç¬¬1é
tokens[0]
ã¤ã¾ã "a"
ã§ããããã«ãshift
ã§å
é è¦ç´ ãåãåºãã¦è©°ããæ»ãå¤ã® "a"
ã足ããã¾ããããã¦ã["b", "c"]
ã¨ãã2è¦ç´ ã®é
åã¨ãªã£ããã®ã®æåã®è¦ç´ "b"
ã« "aa"
ã代å
¥ããã¾ãã
ãããã«PHPã¯ãè¨èªã¨ãã¦ã®ç¾ããã®ç¹ã§ã¯å£ãã¾ããããããããããå ç®ã¨ä»£å ¥ãã¯ãå ç®ä»£å ¥ãã¨ç価ã§ããã¨ããè¨èªä»æ§ã¯ããã¹ã¦ã®å¦çç³»ã§ä¿è¨¼ãããã®ã§ããããããå ç®ä»£å ¥ãã¨ããç価å¤æã§ããªãå¥ã®æ¼ç®ãããã®ã ã¨èããã°ã©ãã§ããã? ããèããã¨PHPã¯ã人éãããèªç¶ãªæèã«åããã¦ããå ç®ã¨ä»£å ¥ãããå ç®ä»£å ¥ãã¨ç価ã§ã¯ãªãå¦çç³»ãé¸ãã§ããã¨ãè¨ãã¾ãã
ã¾ãããããããã¨ã§ããã
<?php function eval_right_then_set_to_left() { $tokens = array("a", "b", "c"); // å³è¾ºã®å¤ $right = array_shift($tokens); // 左辺ã«å ¥ãå¤ãç®åº $left = $tokens[0] . $right; // ä»£å ¥ã®ã¨ãã $tokens[0] = $left; ptint_r($tokens); }
ãããããäºè ãç価ã§ãªããã°ãªããªãçç±ã£ã¦ãããã§ãããããCè¨èªã¨éããã? éãè¨èªã¯éãå¦çç³»ãæã£ã¦ãã¦å½ç¶ã§ãããCã¯ã³ã³ãã¤ã©ã«ã¨ã£ã¦ã³ã³ãã¯ããªä»æ§ã ã£ãããç価ã«ããã ããããã«ã¼ã«ãå°ãªãã»ããææ³ã®å¦ç¿ã³ã¹ããä½ã? è¨èªã®ææ³ãªãã¦ä»ã®å¦ç¿ã®ç·ã³ã¹ãã«æ¯ã¹ããä½ãã§ããããããã¥ã¢ã«ã«ãåããããªãããã¨æ¸ãã¦ããã°ããå¦ã¹ã°ãããã§ããã
$a = 3; $a += 5; // $a ã 8 ã«ã»ãããã¾ãã$a = $a + 5; ã¨åãã§ãã
ã®ã£ãã³
ã...ãããªãã¨ãå®ç³ç³»ã®è¨èªã®äººã«ç¥ããããã¾ãã¯ã¦ããçä¸ããã«éããªãããããéå¤ä¸åºã ãããªããã¢ã¬ã¿ãããªè©±ã ãªã
ã¨æã£ããã§ããã試ãã«æ®æ®µãã¾ã使ããªãPerlã§ããã£ã¦ã¿ã¾ããã
# å ç®ãã¦ä»£å ¥ @tokens = ("a", "b", "c"); $tokens[0] = $tokens[0] . shift(@tokens); print join(',', @tokens) . "\n"; # å ç®ä»£å ¥æ¼ç®å @tokens = ("a", "b", "c"); $tokens[0] .= shift(@tokens); print join(',', @tokens) . "\n";
ã¨ããã¼
aa,c b,c
ãªãã¨ã誰ãæå¾ ããªãã£ãçµæãè¿ãè¨èªã¯å®ã¯Perlã§ããã
ãããçµæã®è§£éããããæ·±ãã§ããããªãããããªæã? ãã£ããå
¥ãã "aa"
ãæå¾ã«æ¶ãã¡ããããã¼ããããããªãã
@tokens = ("a", "b", "c"); $tokens[0] .= $tokens[0]; # shiftããã®æ»ãå¤ã®ã¿ shift(@tokens); # shiftã®å®è¡ãã®ãã® print join(',', @tokens) . "\n";
(ããããã§ç½ãå®ç³ã®æ¹ããã®ããµã«ãªã¯é£ãã§æ¥ãªãã...ã¨æããã ãã©ããããPerlã§ã¯ããæ¸ãã®ãæ®éã ãã¨ããã®ããã£ããæãã¦ãã ãã)
(ãã¯ãã³ã¡ã³ã㧠@tokens[0]
ãã¹ã©ã¤ã¹ã«ãªã£ã¦ãã¨æãã¦ãããã¾ããããã£ã¦ãããã$
ã«ä¿®æ£ãã¦çµæãåã«ãªããã¨ã確èªãã¾ããã)
ã¨ããããã§ãããã£ã¦æã人ã«ãPHPãªãã¦ãã®ã使ããã¨ããããã...ãã¨ãè¨ãããç³»ã®è©±ãããªãã¦ã
è¦ãç®ãã¾ã£ããåããªã®ã«è¨èªå¦çç³»ã«ãã£ã¦éäºææ§ãªã¨ããã¯ããã®ã§ãã©ã®è¨èªã使ãã«ãã¦ããç´æã§äººã«ãã£ã¦è§£éãåããããããªã³ã¼ãã«ãªãããããããå ´åã¯ãä»äººãèªãã§ãããããããèªåã®é ã®ä¸ã«ããç解ã®é ãæ£ãã表ç¾ããã³ã¼ãã«ãã¾ãããã
ã¨ããã®ã大äºã§ããã¨ãã話ã§ããã
ããã£ã¦ãç´ç²é¢æ°åã§åä»£å ¥ãç¦æ¢ããã¹ãã¨ããããã極端ãªè©±ãããªãã¦ãããã°ã©ãã¼ã®ç´ æ´ãªäººéåã£ã¦ã ãã ã¨æãã¾ããå¦çç³»ãéãã°è¨èªä»æ§ã¯éã£ã¦å½ããåãªã®ã«ãèªåã®å¥½ããªã¢ã¬ã¨éããããã¡ãªè¨èªã¨è¨ã£ã¦ãã¾ãã®ã¯è¯ããªããããã¨ããåé¢ãèªã¿ããããã©ããã§ã¯ãªããããããã®ãåãã¦æ¸ããªãã¨ã¢ã³ãªã¼ããã«ã§å¤§å¤ãªãã¨ã«ãªããã ã¨ããå¦ã³ã¨ãã
ãããã£ã¯ã·ã§ã³ãããªãã§ããããã³ãã«ãã£ããã§ããããã
ãããã PHP ã¨ããã°
ãã¡ãããããããé¡ããã¾ãï¼
ãªããPHPã¨ã³ã¸ãã¢é¤æèªæ¬ãã¯Amazoné¨éã©ã³ãã³ã°ã§ããããåãã®ã
- ä½è : æ°åé å¸,åç°åº·ç,å°å±±å²å¿,ç°ä¸ä¹ è¼,ä¿ç§ä¸æ,大æåµå¤ªé,å¢æ°¸ç²,PHPã¨ã³ã¸ãã¢é¤æèªæ¬ç·¨éé¨
- åºç社/ã¡ã¼ã«ã¼: æè¡è©è«ç¤¾
- çºå£²æ¥: 2013/09/13
- ã¡ãã£ã¢: 大åæ¬
- ãã®ååãå«ãããã°ãè¦ã