text
stringlengths 1
254
| output
stringlengths 2
255
|
---|---|
You cannot prepend it to function or class definitions, or conditional structures such as if and foreach, and so forth.
|
泚æ @æŒç®åã¯ãåŒã§ã®ã¿åäœããŸããåºæ¬çãªã«ãŒã«ã¯æ¬¡ã®ããã«ãªããŸãã å€ãåŸãããšãã§ãããã®ã®å Žåã@æŒç®åãåã«ä»ããããšãå¯èœã§ãã äŸãã°ã倿°ã颿°ã include() ã³ãŒã«ã宿°çã® åã«ãã®æŒç®åãã€ããããšãå¯èœã§ãã颿°ãŸãã¯ã¯ã©ã¹ã®å®çŸ©ã if ã foreach çã®ãããªæ¡ä»¶æ§ é ã®åã«ãã®æŒç®åãä»ããããšã¯ã§ããŸããã
|
Warning
|
error_reporting() ãåç
§äžããã
|
Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.
|
çŸåšã誀差å¶åŸ¡æŒç®åãã¬ãã£ãã¯ã¹"@"ã¯ãã¹ã¯ãªããã®å®è¡ãçµäºã ããããªèŽåœçãªãšã©ãŒã®åºåããæå§ããŸãããã®ããããã颿°ã® ãšã©ãŒåºåãæå¶ããããã« "@" ã䜿çšããå Žåããã®é¢æ°ãå©çšã§ã ãªãã£ããããã¹ã¿ã€ãããã£ãå Žåã§ããåå ã瀺ãããšãªããã®å Ž æã§ã¹ã¯ãªããã¯çµäºããŠããŸããŸãã
|
$output = `ls -al`; echo "pre $output / pre";
|
PHP ã¯1çš®é¡ã®å®è¡æŒç®åãããã¯ã¯ã©ãŒã (``) ããµããŒãããŸããã· ã³ã°ã«ã¯ã©ãŒãã§ã¯ãªãããšã«æ³šæããŠãã ãã!PHP ã¯ãåŸæ¹åŒçšç¬Šã® äžèº«ãã·ã§ã«ã³ãã³ããšããŠå®è¡ããããšããŸããåºåãè¿ãããŸãã (ããªãã¡ãåºåãåã«ãã³ãããã®ã§ã¯ãªãã倿°ã«ä»£å
¥ããããšãã§ ããŸãã)
|
See also escapeshellcmd(), exec(), passthru(), popen(), shell_exec(), and system().
|
泚æ ããã¯ã¯ãªãŒãæŒç®åã¯ã ã»ãŒãã¢ãŒã ãæå¹ãªå Žåã ããã㯠shell_exec() ãç¡å¹ãªå Žåã¯ç¡å¹ãšãªããŸãã
|
Incrementing / Decrementing Operators
|
escapeshellcmd(), exec(), passthru(), popen(), shell_exec(), system() ãåç
§ããŠäžããã
|
For example, in the expression 1 + 5 * 3, the answer is 16 and not 18 because the multiplication ("*") operator has a higher precedence than the addition ("+") operator.
|
æŒç®åã®åªå
é äœã¯ãäºã€ã®åŒã"ç·å¯ã«"çµåããŠãã床åããæå®ããŸãã äŸãã°ãåŒ 1 + 5 * 3 ã®çã㯠16 ã«ãªãã 18 ãšã¯ãªããŸããã ããã¯ä¹ç®æŒç®å("*")ã¯ãå ç®æŒç®å("+")ããé«ãåªå
é äœãæããã ãã§ããå¿
èŠã«å¿ããŠåŒ·å¶çã«åªå
é äœãèšå®ããããã«æ¬åŒ§ã䜿çšãã ããšãå¯èœã§ããäŸãã°ã 18 ãšè©äŸ¡ããããã«ã¯ã (1 + 5) * 3 ãšããŸãã
|
The following table lists the precedence of operators with the lowest-precedence operators listed first.
|
次ã®è¡šã«ç€ºããªã¹ãã¯åªå
é äœãæäœãã®ãã䞊ã¹ãæŒç®åã®åªå
é äœã§ãã
|
Prev
|
衚 11-1æŒç®åã®åªå
é äœ
|
Table 11-5.
|
PHP ã¯Cèšèªåœ¢åŒãå眮ããã³åŸçœ®ã®å ç®åããã³æžç®åããµããŒãããŸãã
|
Returns $a, then increments $a by one.
|
衚 11-5å ç®å/æžç®å
|
Here 's a simple example script:
|
以äžã«ç°¡åãªã¹ã¯ãªããã®äŸã瀺ããŸãã
|
! $a
|
衚 11-6è«çæŒç®å
|
The reason for the two different variations of "and" and "or "operators is that they operate at different precedences. (See Operator Precedence.)
|
"and" ããã³ "or" æŒç®åã2çš®é¡ããã®ã¯ãæŒç®ãè¡ãããéã®åªå
é äœãç°ãªã£ãŠããããã§ãã (æŒç®åã®åªå
é äœ ãåç
§äžããã)
|
The second is the concatenating assignment operator ('.='), which appends the argument on the right side to the argument on the left side.
|
æååã®æŒç®åã¯2çš®é¡ãããŸããæåã®ã¯çµåæŒç®å('.')ã§ãå³åŒæ°ãš å·ŠåŒæ°ãçµåãããã®ãè¿ããŸãã2çªç®ã¯ãçµå代å
¥æŒç®å('.=')ã§ã ãã®æŒç®åã¯å³åŽã®åŒæ°ã«å·ŠåŽã®åŒæ°ã远å ããŸãã詳现ã¯ã 代å
¥æŒç®å ãåç
§äž ããã
|
function foo ($var) {$var = $GLOBALS["baz"];} foo($bar);
|
äžèšã®ããã«ããªãã¡ã¬ã³ã¹ã¯ãã€ã³ã¿ã§ã¯ãããŸããããã®ãããæ¬¡ã® äŸã¯æåŸ
éãã«åäœããŸããã
|
The syntax is as follows:
|
ãªãã¡ã¬ã³ã¹ã«ãã颿°ã«å€æ°ãæž¡ãããšãå¯èœã§ãããã®å Žåã颿°å
ã§ãã®åŒæ°ãä¿®æ£å¯èœã«ãªããŸããæ§æã¯æ¬¡ã®ããã«ãªããŸãã
|
Following things can be passed by reference:
|
次ã®ãã®ã¯ãªãã¡ã¬ã³ã¹ã§æž¡ãããšãå¯èœã§ãã
|
New statement, i.e. foo( new foobar())
|
倿°ãããªãã¡ã foo($a)
|
function bar() {$a = 5; return $a;} foo(bar());
|
new åœä»€ãããªãã¡ã foo(new foobar())
|
For example, the following examples of passing by reference are invalid:
|
颿°ããè¿ããããªãã¡ã¬ã³ã¹ã¯ã次ã®ããã«ãªããŸãã
|
Prev
|
ä»ã®åŒã¯ãçµæãæªå®çŸ©ãšãªãããããªãã¡ã¬ã³ã¹ã§æž¡ãã¹ãã§ã¯ãã㟠ãããäŸãã°ããªãã¡ã¬ã³ã¹ã§æž¡ã次ã®äŸã¯ãç¡å¹ã§ãã
|
When returning references, use this syntax:
|
ãªãã¡ã¬ã³ã¹ãè¿ãããšã¯ãçµåãã倿°ãèŠä»ããããã«é¢æ°ã䜿çšã ããå Žåã«äŸ¿å©ã§ãããªãã¡ã¬ã³ã¹ãè¿ãå Žåãæ¬¡ã®æ§æã䜿çšããŠäžã ãã
|
Prev
|
泚æ ãã©ã¡ãŒã¿ãæž¡ãå Žåãšç°ãªããããã§ã¯ãéåžžã®ããã«ã³ããŒã§ã¯ãª ããªãã¡ã¬ã³ã¹ã§è¿ãå€ãæå®ãããªãã¡ã¬ã³ã¹çµåãæå®ããããã« äž¡æ¹ã®å Žæã§ ã䜿çšããå¿
èŠããããŸãã $foo ã«ã€ããŠè¡ãããã®ã¯ãéåžžã®ä»£å
¥ã§ã¯ãã㟠ããã
|
Some constructs, like passing and returning by-reference, are mentioned above.
|
PHPã®å€ãã®æ§ææ§é ã¯ããªãã¡ã¬ã³ã¹æ©æ§ãå©çšããŠå®è£
ãããŠããŸãã ãã®ãããåèšã®ãªãã¡ã¬ã³ã¹çµåã«é¢ããäºé
ã¯ãããã®æ§é ã«ã€ã㊠ãé©çšãããŸãããªãã¡ã¬ã³ã¹æž¡ãããã³ãªãã¡ã¬ã³ã¹ã®è¿ãå€ã®ãã㪠ããã€ãã®æ§é ã«ã€ããŠåç¯ã§èšè¿°ãããŠããŸãããªãã¡ã¬ã³ã¹ã䜿çšã ãä»ã®æ§é ã«ã¯æ¬¡ã®ãã®ããããŸãã
|
When you declare variable as global $var you are in fact creating reference to a global variable.
|
倿°ã global $var ãšããŠå®£èšããå Žåãå®éã«ã¯ ã°ããŒãã«å€æ°ãžã®ãªãã¡ã¬ã³ã¹ãäœæããããšã«ãªããŸãããã®æå³ ã¯ã次ã®äŸãšåãã§ãã
|
$var = $GLOBALS[ "var"];
|
ããã¯ãäŸãã°ã $var ãåé€ããŠãã°ããŒãã«å€æ° ã¯åé€ãããªãããšãæå³ããŸãã
|
In an object method, $this is always reference to the caller object.
|
ãªããžã§ã¯ãã®ã¡ãœããã§ã¯ã $this ã¯åžžã«ã³ãŒã« åŽã®ãªããžã§ã¯ããžã®ãªãã¡ã¬ã³ã¹ã§ãã
|
This does not mean that variable content will be destroyed.
|
ãªãã¡ã¬ã³ã¹ãåé€ããããšã¯ãã¡ããã©å€æ°åãšå€æ°ã®å
容ã®çµåãè§£ é€ããããšã«çžåœããŸããããã¯ã倿°ã®å
容ãç Žæ£ãããããšãæå³ã ãŸãããäŸãã°ã
|
Again, it might be useful to think about this as analogous to Unix unlink call.
|
ããã§ããUNIXã® unlink ã³ãŒã«ãšé¡äŒŒãããã®ãšè ãããšäŸ¿å©ã§ãã
|
Meaning, when you do:
|
PHPã®ãªãã¡ã¬ã³ã¹ã«ããäºã€ã®å€æ°ãåãå
容ãåç
§ããããšãå¯èœã§ ããã€ãŸãã以äžã®ãããªãã®ãå®è¡ããå Žåã§ãã
|
$bar = new fooclass(); $foo = find_var ($bar);
|
泚æ ããã§ã $a ãš $b ã¯å®å
šã«åã ã§ã $a ã $b ãæããŠãããã ã§ã¯ãªãããã®éã§ããããŸããã $a ãš $b ã¯åãå ŽæãæããŠããã®ã§ãã
|
If you use $this in the class it will operate on the current instance of the class.
|
åãæ§æã¯ããªãã¡ã¬ã³ã¹ãè¿ã颿°ã new æŒç®åã§ ã䜿çšå¯èœã§ãã(PHP 4.0.4 以é)
|
Usually you want to have a single instance to work with, due to performance and memory consumption issues.
|
æ³šæ æŒç®åã䜿çšããªããšãªããžã§ã¯ãã®ã³ããŒã çæãããŸãããã $this ãã¯ã©ã¹ã®äžã§äœ¿çšãããšã ãã®å€æ°ã¯ããã®ã¯ã©ã¹ã®çŸåšã®ã€ã³ã¹ã¿ã³ã¹ãæããŸãã ç¡ãã«å€ãå²ãåœãŠããšã€ã³ã¹ã¿ã³ã¹(ã€ãŸããªããžã§ã¯ã) ã®ã³ããŒãçæããã $this ã¯ã³ããŒãæãããšã« ãªããŸãããã®æåãæãŸãããªãå Žåãããã§ãããããšããã®ãæ®é㯠ããã©ãŒãã³ã¹ãšã¡ã¢ãªå¹çã®é¢ããèããŠåäœããã€ã³ã¹ã¿ã³ã¹ã¯äžã€ ã§ååã ããã§ãã
|
This is a limitation of the Zend Engine and will therefore result in a parser error.
|
@new ã®ããã«äœ¿çšããããšã«ãããã³ã³ã¹ãã©ã¯ã¿ ã«ããããšã©ãŒã @ æŒç®åã䜿çšããããšã ã§ããŸãããããã¯ã new åœä»€ãçšããå Žå㯠åäœããŸãããããã¯ãZend Engineã®å¶éã§ãããããŒã¹ãšã©ãŒã çºçããŸãã
|
This is done by making a local variable in a function and a variable in the calling scope reference to the same content.
|
ãªãã¡ã¬ã³ã¹ã®ç¬¬2ã®äœ¿çšæ³ã¯ã倿°ã®ãªãã¡ã¬ã³ã¹æž¡ãã§ãããã®å Žåã 颿°ã§ããŒã«ã«å€æ°ãäœæãããã³ãŒã«åŽã®å€æ°ãšåãå
容ãžã®ãªãã¡ã¬ ã³ã¹ãšãªããŸããäŸã瀺ããŸãã
|
The third thing reference can do is return by reference.
|
ãªãã¡ã¬ã³ã¹ã®ç¬¬3ã®äœ¿çšæ³ã¯ã ãªãã¡ã¬ã³ã¹ã«ããè¿ãå€ ã§ãã
|
Because you can have another PHP-array as a value, you can also quite easily simulate trees.
|
PHPã®é
åã¯ãå®éã«ã¯é çªä»ãããããããã§ãããããã¯ã å€ ã ã㌠ã«ãããããåã§ ãããã®åã¯ãããã€ãã®ææ³ã§æé©åãããŸãããã®ãããå®éã®é
å ãŸãã¯ãªã¹ã(ãã¯ãã«)ã(ãããããã®å®è£
ã§ãã)ããã·ã¥ããŒãã«ã ãã£ã¬ã¯ããªãã³ã¬ã¯ã·ã§ã³ãã¹ã¿ãã¯ããã¥ãŒçãšããŠäœ¿çšããããšã å¯èœã§ããPHPã®é
åã«ã¯ä»ã®PHPé
åãå€ãšããŠä¿æããããšãã§ããã ããéåžžã«ç°¡åã«ããªãŒæ§é ã衚çŸããããšãå¯èœã§ãã
|
For more information we refer you to external literature about this broad topic.
|
ãããã®æ§é ã«é¢ãã説æã¯ãæ¬ããã¥ã¢ã«ã®ç¯å²å€ã§ããããããã®æ§ é ã«åã
ã«é¢ããäŸãå°ãªããšãäžã€èŠä»ããããšãå¯èœã§ãããããã® æ§é ã«é¢ããããè©³çŽ°ãªæ
å ±ã«ã€ããŠã¯ãããŒã¿æ§é ã«é¢ããè¯æžã賌å
¥ ããŠäžããã
|
It takes a certain number of comma-separated key = value pairs.
|
é
å ã¯ãèšèªæ§é array() ã§äœæ ããããšãå¯èœã§ãããã®æ§é ã¯ãç¹å®ã®æ°ã®ã«ã³ãã§åºåããã key = value ã®çµãåŒæ°ãšããŸãã
|
?php $arr = array( "foo "= "bar", 12 = true); echo $arr["foo"]; / / bar echo $arr[12]; / / 1?
|
key ã¯ãæŽæ° ãŸã㯠æååã§ãã ããããŒããæŽæ°ã®æšæºçãªè¡šçŸåœ¢åŒã§ããå Žåã ãã®ããã«è§£éãããŸãã(ã€ãŸãã '8' 㯠8 ãšããŠè§£éãããŸããäžæ¹ã '08' 㯠'08' ãšããŠè§£éãã㟠ãã)
|
A key is either an integer or a string.
|
å€ã¯ãäœã§ãæ§ããŸããã
|
There are no different indexed and associative array types in PHP, there is only one array type, which can both contain integer and string indices.
|
ããŒãçç¥ããå ŽåãæŽæ°æ·»åã®æå€§å€ã䜿çšãããæ°ããããŒã¯ã ã®æå€§å€+1ãšãªããŸããæŽæ°å€ã¯è² ã®æ°ãšãªãå¯èœæ§ãããããã è² ã®æ·»åãæãããŸããäŸãã°ãæé«æã®æ·»åã -6 ã®å Žåãæ¬¡ã®ããŒã¯ -5 ãšãªããŸãã æŽæ°æ·»åããŸã ååšããªãå ŽåãããŒã¯ 0 (ãŒã)ãšãªããŸãã å€ãæ¢ã«ä»£å
¥ãããŠããããŒãæå®ããå Žåãå
ã®å€ã¯äžæžããããŸãã
|
If you omit a key, the maximum of the integer-indices is taken, and the new key will be that maximum + 1.
|
ããŒãšã㊠true ã䜿çšãããšã integer 1 ãããŒãšããŠè©äŸ¡ãããŸãã ããŒãšã㊠false ã䜿çšãããšã integer 0 ãããŒãšããŠè©äŸ¡ãããŸãã ããŒãšã㊠NULL ã䜿çšãããšãç©ºã®æååãšããŠè©äŸ¡ ãããŸããããŒãšããŠç©ºã®æååã䜿çšãããšãç©ºã®æååã®ããŒãšãã®å€ã äœæ(ãŸãã¯äžæžã)ããŸããç©ºã®æ¬åŒ§ãçšããå Žåãšåãã§ã¯ãããŸããã
|
Having e.g. the highest index being -6 will result in -5 being the new key.
|
é
åãŸãã¯ãªããžã§ã¯ããããŒãšããŠäœ¿çšããããšã¯ã§ããŸããã ãããè¡ãªããšãwarning: Illegal offset type ãçºçããŸãã
|
If you specify a key that already has a value assigned to it, that value will be overwritten.
|
æç€ºçã«å€ãèšå®ããããšã«ãããæ¢åã®é
åãä¿®æ£ããããšãå¯èœã§ ãã
|
Using TRUE as a key will evalute to integer 1 Using TRUE as a key will evalute to integer 1 as key.
|
ããã¯ãè§æ¬åŒ§ã®äžã«ããŒãæå®ããããšã«ãããé
åã«å€ã代å
¥ãã ããšã«ããè¡ãããšãå¯èœã§ããããŒãçç¥ããããšãå¯èœã§ãããã® å Žåã空ã®è§æ¬åŒ§(" [] ")ã®å€æ°åãšããŠè¿œå ã㊠äžããã
|
Using an emptry string as key will create (or overwrite) a key with an empty string and its value, it is not the same as using empty brackets.
|
é
åã§äœ¿çšãã䟿å©ãªé¢æ°ããããããããŸãã é
å颿° ã®ç¯ãåç
§äžããã
|
This is done by assigning values to the array while specifying the key in brackets.
|
泚æ unset() 颿°ã¯é
åã®ããŒãåé€ããããšãåºæ¥ãŸãã ãã ããããã«ãã£ãŠã€ã³ããã¯ã¹ã®åæ§ç¯ãè¡ãããããã§ã¯ ãªã ãšããããšã«æ°ãã€ããŠãã ããã
|
$arr[ key] = value; $arr[] = value; / / key is either string or nonnegative integer / / value can be anything
|
å¶åŸ¡æ§é foreach ãé
åçšã«éå®ããŠååšããŸãããã®æ§é ã¯ãé
åã®èŠçŽ ã«ç°¡åã«é£ç¶ çã«ã¢ã¯ã»ã¹ããææ®µãæäŸããŸãã
|
Note:
|
å€ãã¹ã¯ãªããã§æ¬¡ã®ãããªæ§æãèŠãããšããããããããŸããã
|
This works but also throws a PHP error of / / level E_NOTICE because of an undefined constant named fruit / / / / Notice:
|
å°æ¥çã«ãPHPã¯ä»ã®å®æ°ãŸãã¯ããŒã¯ãŒãã远å ããããšæãããã ãããåé¡ãšãªãå¯èœæ§ããããŸããäŸãã°ãçŸåšã§ãã åèª empty ããã³ default ã䜿çšããããšã¯ã§ããŸããã ããã¯ããããããç¹å¥ãª äºçŽæžã¿ã®ããŒã¯ãŒã ã§ãã ããã§ãã
|
We / / will assign value 'veggie' to a constant named fruit. define('fruit' ,'veggie'); / / Notice the difference now print $arr['fruit']; / / apple print $arr[fruit]; / / carrot / / The following is okay as it's inside a string.
|
泚æ error_reporting ã E_ALL ã«å€ããå ŽåãPHPããã®æ§é ã䜿çšãã ãŠãããšããèŠä»ãã床ã«èŠåãçæãããŸãããã®æ©èœã¯ãä»ã®é å»ã®ãæ©èœãã«ã€ããŠãæå¹ã§ãã (ã¹ã¯ãªããã«è¡ error_reporting(E_ALL); ã 眮ããŠäžãã)
|
By default, error_reporting is turned down to not show them.
|
泚æ 2éåŒçšç¬Šã§æ¬ããã string ã®äžã§ä»ã®æ§æãæå¹ã§ãã ãã詳现ã«ã€ããŠã¯ã æååã®äžã®å€æ° ãåç
§äžããã
|
That means that you can write things like this:
|
PHPã®é
ååã¯éåžžã«è§£ãã«ãããããããã§ãé
åã®åŒ·åãªæ©èœã瀺ã ããã€ãã®äŸã玹ä»ããŸãã
|
?php $error_descriptions[ 1] = "A fatal error has occured"; $error_descriptions[2] = "PHP issued a warning"; $error_descriptions[8] = "This is just an informal notice";?
|
äŸ 7-4array()ã®äœ¿çšäŸ
|
It works, because bar is due to its syntax expected to be a constant expression.
|
äŸ 7-5ã³ã¬ã¯ã·ã§ã³
|
At some point in the future, the PHP team might want to add another constant or keyword, or you may introduce another constant into your application, and then you get in trouble.
|
é
åã®å€ããã®ãããªã«ãŒãã§çŽæ¥å€æŽããããšã¯ã§ããªãããšã«æ³šæ ããŠäžããã ããã解決ããã«ã¯ã次ã®ããã«ããŸãã
|
Note:
|
äŸ 7-6ã³ã¬ã¯ã·ã§ã³
|
See the above examples for details on why as well as the section on variable parsing in strings.
|
ãã®äŸã¯ã1ããå§ãŸãé
åãäœæããŸãã
|
If you convert an object If you convert an object to an array, you get the properties (member variables) of that object as the array's elements.
|
äŸ 7-71ããå§ãŸãæ·»å
|
Array ([0] = RED [1] = BLUE [2] = GREEN [3] = YELLOW) * /?
|
é
åã«ã¯é çªãä»ããããŸããç°ãªã£ããœãŒã颿°ãçšããŠé çªãå€æŽ ããããšãå¯èœã§ããããè©³çŽ°ãªæ
å ±ã«ã€ããŠã¯ã é
å颿° ãåç
§äžããã
|
Array ([1] = 'January '[2] = 'February' [3] = 'March ') * /
|
äŸ 7-9é
åã®ãœãŒã
|
Arrays are ordered.
|
é
åã®å€ã¯äœã§ãè¯ãããããã®å€ãä»ã®é
åãšããããšãå¯èœã§ãã ããã«ãããååž°çãªé
åã倿¬¡å
ã®é
åãäœæããããšãå¯èœã§ãã
|
?php $arr1 = array( 2, 3); $arr2 = $arr1; $arr2[] = 4; / / $arr2 is changed, / / $arr1 is still array(2,3) $arr3 = $arr1; $arr3[] = 4; / / now $arr1 and $arr3 are the same?
|
äŸ 7-10ååž°ããã³å€æ¬¡å
é
å
|
A boolean A boolean expresses a truth value.
|
è«çåã¯ãæãç°¡åãªåã§ãã boolean ã¯ãçåœã®å€ã衚 ããŸãããã®å€ã¯ã TRUE ãŸã㯠FALSE ã®ã©ã¡ããã«ãªããŸãã
|
Note:
|
泚æ booleanåã¯ãPHP 4ã§å°å
¥ãããŸããã
|
To specify a boolean literal, use either the keyword TRUE or FALSE.
|
booleanãªãã©ã«ãæå®ããã«ã¯ãããŒã¯ãŒã TRUE ãŸã㯠FALSE ãæå®ããŠäžãããäž¡æ¹ãšã倧æåå° æåã«äŸåããŸããã
|
Usually you use some kind of operator which returns a boolean value, and then pass it on to a control structure.
|
éåžžã boolean åã®å€ãè¿ã æŒç®å ã䜿çšããŠããã å¶åŸ¡æ§é ã«ãã®çµæãæž¡ ããŸãã
|
To explicitly convert a value to boolean, use either the (bool) or the (boolean) cast.
|
boolean ã«æç€ºçã«å€æãè¡ãã«ã¯ããã£ã¹ã (bool) ãŸã㯠(boolean) ã 䜿çšããŸããããããæŒç®åã颿°ãå¶åŸ¡æ§é ã boolean åã®åŒæ°ãå¿
èŠãšããå Žåã«ã¯ãå€ã¯èªåçã«å€æããããããå€ãã® å Žåããã£ã¹ãã¯äžèŠã§ãã
|
However, in most cases you do not need to use the cast, since a value will be automatically converted if an operator, function or control structure requires a boolean argument.
|
åã®çžäºå€æ ãåç
§äžããã
|
When converting to boolean, the following values are considered FALSE:
|
boolean ã«å€æããå Žåãæ¬¡ã®å€ã¯ FALSE ãšã¿ãªãããŸãã
|
the integer 0 (zero)
|
boolean ã® FALSE
|
the empty string, and the string "0"
|
integer ã® 0 (㌠ã)
|
an object with zero member variables
|
float ã® 0.0 (ãŒã)
|
Warning
|
空㮠æåå ã ããã³ æåå ã® "0"
|
Home
|
ãŒããèŠçŽ ãšãã ãªããžã§ ã¯ã
|
Types
|
ç¹å¥ãªå€ NULL (å€ãã»ãã ãããŠããªã倿°ãå«ã)
|
Integers
|
-1 ã¯ãä»ã®ãŒãã§ãªãæ°ãåæ§ã«(æ£è² ã«ãã ã) TRUE ãšã¿ãªãããŸãã
|
?php $a = 1.234; $b = 1.2e3; $c = 7E-10;?
|
("float","double","宿°"ã®ãããª) ãããŒãæ°ã¯ãæ¬¡ã®æ§æã«ããæå® ã§ããŸãã
|
This can lead to confusing results: for example, floor( (0.1+0.7)*10) will usually return 7 instead of the expected 8 as the result of the internal representation really being something like 7.9999999999....
|
0.1 ã 0.7 ã®ãã㪠簡åãªå°æ°è¡šçŸãè¥å¹²ç²ŸåºŠã倱ãããšãªãå
éšçãª2é²è¡šçŸã«å€ æããããšã¯ã§ããŸãããããã«ãããæ··ä¹±ããçµæãçããããšãã ããŸããã€ãŸãã floor((0.1+0.7)*10) ã¯ äºæ³ããã 8 ã®ä»£ããã«å®éã®å
éšè¡šçŸã®çµæãšã ㊠7.9999999999... ã®ãããªãã®ãçµæãšããŠè¿ã ãŸãã
|
If you really need higher precision, you should use the arbitrary precision math functions or gmp functions instead.
|
ããã¯ãããã€ãã®åæ°ã¯æéã®æ¡æ°ã®å°æ°ç¹è¡šèšã§æ£ç¢ºã«è¡šçŸã§ã㪠ããšããäºå®ã«é¢ä¿ããŠããŸããäŸãã°ã 1/3 ã®å° æ°ç¹è¡šèšã¯ã 0.3333333... ãšãªããŸãã
|
For values of other types, the conversion is the same as if the value would have been converted to integer and then to float.
|
ãã£ãŠãå°æ°ã®æåŸã®æ¡ãä¿¡çšããŠã¯ãããŸããããå°æ°ãçãããšã ãæ¯èŒãè¡ã£ãŠã¯ãããŸãããããé«ã粟床ãå¿
èŠãªå Žåã«ã¯ã ä»»æç²ŸåºŠæ°åŠé¢æ° ãŸã㯠gmp 颿°ã代ããã«äœ¿çšããŠäžããã
|
Prev
|
PHPã¯ã8çš®é¡ã®åºæ¬åããµããŒãããŸãã
|
PHP supports eight primitive types.
|
4çš®é¡ã®ã¹ã«ã©ãŒå:
|
Four scalar types:
|
è«çå€(boolean)
|
integer
|
æŽæ°(integer)
|
floating-point number (float)
|
æµ®åå°æ°ç¹æ°(float)
|
array
|
æåå(string)
|
object
|
é
å(array)
|
NULL
|
ãªããžã§ã¯ã(object)
|
number
|
ãªãœãŒã¹(resource)
|
callback
|
ãã«(NULL)
|
Note:
|
泚æ ãã®ããã¥ã¢ã«ã«ã¯ããã°ãã° mixed ãšãããã© ã¡ãŒã¿ãçŸããŸãããã®ç䌌çãªåã¯ããã®ãã©ã¡ãŒã¿ã«é¢ããŠè€æ°ã® åã䜿çšå¯èœã§ããããšã瀺ããŸãã
|
Note:
|
倿°ã®åã¯ãåºæ¬çã«ããã°ã©ãã«ããã»ãããããŸããããããããã®å€ æ°ã䜿çšãããæã®å
容ã«å¿ããŠPHPã«ããå®è¡æã«æ±ºå®ãããŸãã
|
To check for a certain type, do not use gettype(), but use the is_ type functions.
|
泚æ ãã åŒ ã®åãšå€ãæ£ç¢ºã« ç¥ãããå Žåã¯ã var_dump() 颿°ã䜿çšããŠãã ããã
|
If you would like to force a variable to be converted to a certain type, you may either cast the variable or use the settype() function on it.
|
ãã倿°ã®åã匷å¶çã«ä»ã®åã«å€æãããå Žåã倿°ã ãã£ã¹ã ãããã settype() 颿°ã䜿çšããŸãã
|
For more information, see the section on Type Juggling.
|
倿°ã¯ããã®åã«äŸåããŠç°ãªã£ãåäœãããå Žåãããããšã« 泚æããŠãã ãããè©³çŽ°ãªæ
å ±ã«ã€ããŠã¯ã åã®å€æ ã®ã» ã¯ã·ã§ã³ãåç
§äžããã
|
An integer is a number of the set Z = {..., -2, -1, 0, 1, 2,...}.
|
integer ã¯ãZ = {..., -2, -1, 0, 1, 2, ...}ãšããéå ã§ãã
|
Arbitrary length integers and Floating point numbers
|
ä»»æç²ŸåºŠæŽæ° ããã³ float ãåç
§äžããã
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.