PHPã¨JavaScriptã®é åãé£æ³é åããã£ã¡ãã«ãªãã®ã§ãæ´çãã¦ã¿ã
PHPï¼ãµã¼ãã¼ãµã¤ãï¼ ââ JavaScriptï¼ã¯ã©ã¤ã¢ã³ããµã¤ãï¼ãããé ã®ä¸ã§ãã£ã¡ãã«ãªãã®ã§ããã使ããé
åã»é£æ³é
åã¨ãã®èµ°æ»ãã«ã¤ãã¦æ´çãã¦ã¿ããå
ãã¿ã¯ã以前のエントリã§ãç´¹ä»ãããゆーすけべーさんのエントリã
é å
PHP
<?php $foods = array('ã©ã¼ã¡ã³', '寿å¸', 'ã«ã¬ã¼', 'ã¹ãã²ããã£', 'ã¹ãã¼ã'); foreach ($foods as $v) { echo 'I like ' . $v . '<br>'; }
JavaScript
var foods =['ã©ã¼ã¡ã³', '寿å¸', 'ã«ã¬ã¼', 'ã¹ãã²ããã£', 'ã¹ãã¼ã']; var len = foods.length; for (var i = 0; i < len; i++) { document.write('I like' + foods[i] + '<br>'); }
é£æ³é å
PHP
<?php $ore = array( 'name' => 'maeharin', 'tall' => 169 ); foreach ($ore as $k => $v) { echo $k . 'ã¯' . $v . '<br>'; }
JavaScript
var ore = { name : 'maeharin', tall : 169 }; for (var k in ore) { document.write(k + 'ã¯' + ore[k] + '<br>'); }
â»JavaScriptã®é£æ³é
åã¯ããªãã¸ã§ã¯ã
é åï¼é£æ³é å
PHP
<?php $people = array( array( 'name' => 'Kãã', 'tall' => 160 ), array( 'name' => 'Yãã', 'tall' => 182 ), array( 'name' => 'Tãã', 'tall' => 148 ) ); foreach($people as $v) { echo $v['name'] . 'ã®èº«é·ã¯' . $v['tall'] .'<br>'; }
JavaScript
var people = [ { name : 'Kãã', tall : 160 }, { name : 'Yãã', tall : 182 }, { name : 'Tãã', tall : 148 } ]; var len = people.length; for (var i = 0; i < len; i++) { document.write(people[i].name + 'ã®èº«é·ã¯' + people[i].tall + '<br>'); }
é åï¼é£æ³é åï¼é å
PHP
<?php $people = array( array( 'name' => 'Kãã', 'foods' => array('ã«ã¬ã¼', 'ã©ã¼ã¡ã³') ), array( 'name' => 'Yãã', 'foods' => array('ãã³ãã¼ã¬ã¼', 'ç丼', 'ããã³') ), array( 'name' => 'Tãã', 'foods' => array('ãµã©ã') ) ); foreach ($people as $v) { foreach ($v['foods'] as $food) { echo $v['name'] . 'likes' . $food . '!!<br>'; } }
JavaScript
var people = [ { name : 'Kãã', foods : ['ã«ã¬ã¼', 'ã©ã¼ã¡ã³'] }, { name : 'Yãã', foods : ['ãã³ãã¼ã¬ã¼', 'ç丼', 'ããã³'] }, { name : 'Tãã', foods : ['ãµã©ã'] } ]; var len = people.length; for (var i = 0; i < len; i++) { var len_f = people[i].foods.length; for (var j = 0; j < len_f; j++) { document.write(people[i].name + 'likes' + people[i].foods[j] + '!!<br>'); } }
PHPã¯æ¸ãæ¹ä¸ã¤ã ãã©ãJavaScriptã¯æ¸ãæ¹ãä½éãããã
æ¸ãæ¹ã®ãã¿ã¼ã³ã¯ãjavascriptã§è¶ æåãªid:amachangã«ããã以ä¸ã®ã¨ã³ããªã§ç¶²ç¾ ããã¦ãã
Google JavaScript Style Guide
ã¡ãªã¿ã«ãGoogleã®JavaScript Style Guideã§ã¯ãé åãªãã©ã«ï¼[]ï¼ã¨ãªãã¸ã§ã¯ããªãã©ã«ï¼{}ï¼ãç¨ããæ¹ãããã¨æ¸ãã¦ããã
Google JavaScript Style Guide(和訳)
以ä¸ãPHPã¨JavaScriptã¯å¹³è¡ãã¦ä½¿ããã¨ãå¤ãã®ã§ãç´ããããã¨ããã¯ãããã£ã¦æ´çãã¦ãããã