ã¾ã PHPã®é åã®ä»æ§ãããç解ããã¦ããªãæ¹ã¸
ãPHPã使ããããDISã£ã¦ãåé㸠- Qiitaãã¨ããè¨äºãããã¾ããã
æ¦ãæ£ç¢ºãªå 容ã§ãããã¾ã æ ¹æ¬çã«PHPã®é åã®ä»æ§ãããã£ã¦ããªããããªè¨è¿°ãä¸é¨ã«è¦åãããã¾ããã端çãªãã®ã以ä¸ã§ãã
ä»ã¾ã§è©±ããããã«PHPã«ã¯é ååã¨è¾æ¸åã¯ææ§ãªãã®ã§ãã
ãããããã°ã©ãã³ã°è¨èªã®å®è£ ã«ããã¦åãææ§ã¨ãããã¨ã¯ãããã¾ãããå é¨çã«ã¯åã¯å³å¯ã§ããã§ãªããã°å®è£ ã§ãã¾ããã
ãã ããèªåçã«åãå¤ãããã¨ããããã¦ã¼ã¶ã®ç解ãææ§ã ã¨ãè¨èªã®ä»æ§ãææ§ã«æããã¨ãããã¨ã§ãã
ã¨ãããã¨ã§ãPHPã®é åã«ã¤ãã¦ããç解ãã¦ããªãPHPã¦ã¼ã¶ãã¾ã ããã§ããããããä»æ§ã«ã¤ãã¦å°ãè¨äºãæ¸ããã¨ã«ãã¾ãã
PHPã®é åã¨ã¯ï¼
PHPã®é åã«ã¤ãã¦ç¥ã£ã¦ããã¹ããã¨ã¯ä»¥ä¸ã§ã¯ãªããã¨æãã¾ãã
- PHPã®é åã¯arrayåã®1ã¤ãããªã
- PHPã®é åã¯é çªãä¿æãã¦ãã
- é åã®ãã¼ã®åã¯æ´æ°ã¨æååãããªãã両è ã¯åºå¥ããã
- é åã®ãã¼ã«ã¯æé»ã®åå¤æãèµ·ããï¼
é åã®ãã¼ã®æé»ã®åå¤æ
ãã¦ãåé¡ã§ãã以ä¸ã®çµæã¯ï¼
<?php
$a = [
'1' => 'one',
];
$b = [
1 => 'one',
];
var_dump($a === $b);
çãã¯true
ã§ãã
ä½æ
ãªãã$a
ã®ãã¼'1'
ã¯ãæ´æ°ã«ãã£ã¹ããããããã§ãã
$a
ããã³ããã¦è¦ãã¨ã以ä¸ã®ããã«ãã¡ããã¨æ´æ°ã«ãªã£ã¦ãã¾ãï¼1
ã®åå¾ã«ã¯"
ã¯ããã¾ããï¼ã
array(1) {
[1]=>
string(3) "one"
}
ä»ã«ãfloatãboolãnullã®å¤ããã¼ã«æå®ããå ´åãæé»ã®åå¤æãèµ·ããã¾ãããã¦ã¼ã¹ã±ã¼ã¹ã¯å°ãªãã®ã§ã¯ãªããã¨æãã¾ããæ°ã«ãªã人㯠PHPããã¥ã¢ã« ãåç §ãã¦ãã ããã
ã¾ã ãä¿¡ãã¦ããªã人ãããããç¥ãã¾ããã®ã§ãä¼¼ããããªåé¡ãããä¸ã¤ã以ä¸ã®çµæã¯ï¼
<?php
$a = [
'1' => 'string',
1 => 'int',
];
var_dump($a);
ããã¯ãã©ã¡ãã®ãã¼ãåãæ´æ°ã®1ãªã®ã§ãå¾ã«è¨è¿°ããã¦ããè¦ç´ ã§ä¸æ¸ãããã¾ãã
array(1) {
[1]=>
string(3) "int"
}
ãã¦ã次ã®åé¡ã§ãã以ä¸ã®çµæã¯ï¼
<?php
$a = [ "*" => "asterisk", "@" => "atmark" ];
$b = [ "20" => "twenty", "30" => "thirty" ];
$c = array_merge($a, $b);
var_dump($c);
ããã¯ä»¥ä¸ã®ããã«ãªãã¾ããarray_merge()ã§ã¯ããã¼ãæ´æ°ã®è¦ç´ ã¯0ããæ¯ãç´ããã¾ãã
array(4) {
["*"]=>
string(8) "asterisk"
["@"]=>
string(6) "atmark"
[0]=>
string(6) "twenty"
[1]=>
string(6) "thirty"
}
æ´æ°ã®ãã¼ã¨æååã®ãã¼ã¯æ±ããç°ãªããã¨ããããã¾ãã
æ´åæ§ã«ã¤ãã¦
ç´æ¥é¢ä¿ãªãã§ããã以ä¸ã®ã©ã¹ãã¹ããã®è¨èã¯ããªããªãèå³æ·±ããã®ã§ãã
ç§ãã¡ãPHPã®æ´åæ§ã®ãªããç´ããªãã¨è¨ã£ã¦ããéé£ãã人ããã¾ããï¼PHPã¯ãããããããåé¡ã«ãªããããªãã®ã§ã¯ãªãã®ã§ããPHPã¯çµå±ï¼ã©ã¤ãã©ãªããã®ä»åºç¤ã¨ãªã£ã¦ãããã¯ããã¸ã¼ã¸ã®ã·ã§ã¼ãã«ããã«ããã¾ããããããªã®ã«ï¼ã©ããã¦èª°ããPHPã¬ãã«ã§ã®æ´åæ§ãæ±ããã®ãï¼ç§ã«ã¯åããã¾ãããæ´åæ§ãã¨ãã®ã¯ãã¬ã¼ã ã¯ã¼ã¯ã®å½¹å²ã§ãã
http://gihyo.jp/news/report/2015/12/1401?page=4 ããã
ãã®èãã«å¾ãã°ãPHPã®é¢æ°ã®å¼æ°ã®é çªãï¼ããã°ã©ãã®ããã¯ã°ã©ã³ãã«ãã£ã¦ã¯ï¼ãããã«ããä»æ§ãªã©ã¯ããã¥ã¢ã«ãèªãã°ããã ãã®æ¬å½ã«ã©ãã§ããããã¨ã§ãã
ã¦ã¼ã¶ãå®éã«ä½¿ãã®ã¯ãã¬ã¼ã ã¯ã¼ã¯ï¼Packagistã§æä¾ããããããªããã±ã¼ã¸ãå«ãã§ããå¼ãã§ããã¨æããã¾ãï¼ã§ããä½æ ããã£ãã¨ããããããã±ã¼ã¸ãæ¸ããªãã®ãï¼ã¨ãããã¨ã«ãªãã¾ãã
ãã®ã©ã¹ãã¹ããã®èãã«è³åãããã©ããã¯ã¨ããããå®éã«PHPã§ã®éçºã¯ãã¬ã¼ã ã¯ã¼ã¯ä¸ã§OOPã§è¡ããã¦ãããã®ã大é¨åã§ãããPHPã®å é¨é¢æ°ãç´æ¥æ±ãæ©ä¼ã¯ã©ãã©ãæ¸ã£ã¦ãããã¨ã¯äºå®ã§ãã
åè
Date: 2015/12/22