Reference - Hvad betyder dette symbol i PHP?
Hvad er det her?
Dette er en samling af spørgsmål, som dukker op af og til om syntaks i PHP. Dette er også en fællesskabswiki, så alle er velkomne til at deltage i vedligeholdelsen af denne liste.
Hvorfor er dette?
Det plejede at være svært at finde spørgsmål om operatorer og andre syntaksetokens.¹
Hovedidéen er at have links til eksisterende spørgsmål på Stack Overflow, så det er nemmere for os at henvise til dem, og ikke at kopiere indhold fra PHP-manualen over.
Bemærk: Siden januar 2013 har Stack Overflow understøttet specialtegn. Du skal blot omgive søgetermerne med anførselstegn, f.eks. [php] "==" vs "==="
2
Hvad skal jeg gøre her?
Hvis du er blevet henvist hertil af nogen, fordi du har stillet et sådant spørgsmål, kan du finde den særlige syntaks nedenfor. De linkede sider til PHP-manualen sammen med de linkede spørgsmål vil sandsynligvis besvare dit spørgsmål derefter. Hvis det er tilfældet, opfordres du til at upvote svaret. Denne liste er ikke ment som en erstatning for den hjælp, som andre har givet.
Listen
Hvis dit særlige token ikke er anført nedenfor, kan du måske finde det i List of Parser Tokens.
&
Bitvise operatorer eller Referencer
- https://stackoverflow.com/questions/1676897
- https://stackoverflow.com/questions/600202
- https://stackoverflow.com/questions/2209934/
- https://stackoverflow.com/questions/2376348
- https://stackoverflow.com/questions/1006652
- https://stackoverflow.com/questions/2297592
- https://stackoverflow.com/questions/2422907
- https://stackoverflow.com/questions/2478149
- https://stackoverflow.com/questions/3957584
- https://stackoverflow.com/questions/4705262
- https://stackoverflow.com/questions/4705838
-
https://stackoverflow.com/questions/21058439 (&$)
=&
Referencer - https://stackoverflow.com/questions/1768343
- https://stackoverflow.com/questions/1367454
- https://stackoverflow.com/questions/3177342
-
https://stackoverflow.com/questions/2081806
- https://stackoverflow.com/questions/1367454
-
https://stackoverflow.com/questions/3177342
- https://stackoverflow.com/questions/2803321
- https://stackoverflow.com/questions/2376348
- https://stackoverflow.com/questions/4746865
-
https://stackoverflow.com/questions/4502092
- https://stackoverflow.com/questions/1934173
-
https://stackoverflow.com/questions/3204919
-
https://stackoverflow.com/questions/2127260
- https://stackoverflow.com/questions/1032161
- https://stackoverflow.com/questions/3551527
- https://stackoverflow.com/questions/3984864
-
https://stackoverflow.com/questions/4872340
- https://stackoverflow.com/questions/1080247
- https://stackoverflow.com/questions/1993409
- https://stackoverflow.com/questions/4055355
-
https://stackoverflow.com/questions/4210187
???
Null Coalesce Operator (siden PHP 7) -
https://stackoverflow.com/questions/7278835
?string
?int
?array
?bool
?float
Deklaration af returtypen kan annulleres (siden PHP 7.1) -
[Nullable return type declaration] (https://stackoverflow.com/a/54217328/250259)
- https://stackoverflow.com/questions/2908095
-
https://stackoverflow.com/questions/4747761
- https://stackoverflow.com/questions/2903564
- https://stackoverflow.com/questions/2588298
- https://stackoverflow.com/questions/3173501
- https://stackoverflow.com/questions/1912902
- https://stackoverflow.com/questions/4120755
-
https://stackoverflow.com/questions/8734823
- https://stackoverflow.com/questions/10788400
-
https://stackoverflow.com/questions/4790020
- https://stackoverflow.com/questions/2588149
- https://stackoverflow.com/questions/3037526
- https://stackoverflow.com/questions/3173501
- https://stackoverflow.com/questions/2316370
-
https://stackoverflow.com/questions/4502587
=>
Arrays - https://stackoverflow.com/questions/1241819
- https://stackoverflow.com/questions/1655336
-
https://stackoverflow.com/questions/4758791
- https://stackoverflow.com/questions/2674920
-
https://stackoverflow.com/questions/2724936
-
https://stackoverflow.com/questions/2790329
-
https://stackoverflow.com/questions/9718689/strange-print-behaviour-in-php
<<<<<
Heredoc eller Nowdoc - https://stackoverflow.com/questions/5539669
- https://stackoverflow.com/questions/1048481
- https://stackoverflow.com/questions/3700042
- https://stackoverflow.com/questions/2090081
-
https://stackoverflow.com/questions/2333779
-
https://stackoverflow.com/questions/2063480
- https://stackoverflow.com/questions/80646
- https://stackoverflow.com/questions/1663451
- https://stackoverflow.com/questions/2063480
-
https://stackoverflow.com/questions/15813490/
- https://stackoverflow.com/questions/1117967
- https://stackoverflow.com/questions/80646
- https://stackoverflow.com/questions/2063480
-
https://stackoverflow.com/questions/15813490/
- https://stackoverflow.com/questions/1298083
-
https://stackoverflow.com/questions/1139154
- https://stackoverflow.com/questions/1663451
- https://stackoverflow.com/questions/1139154
- https://stackoverflow.com/questions/6356826
-
https://stackoverflow.com/questions/9671785/what-is-the-difference-between-and
- https://stackoverflow.com/questions/249312
- https://stackoverflow.com/questions/589391
- https://stackoverflow.com/questions/9671785
-
https://stackoverflow.com/questions/15813490/
<=>
Sammenligningsoperatorer (siden PHP 7.0) -
Rumskibsoperator (trevejssammenligning)
- https://stackoverflow.com/questions/2233835
-
https://stackoverflow.com/questions/13811922
- https://stackoverflow.com/questions/2233835
- https://stackoverflow.com/questions/4502092
- https://stackoverflow.com/questions/5666741
-
https://stackoverflow.com/questions/12213283
-
https://stackoverflow.com/questions/1967360
-
https://stackoverflow.com/questions/2140090
+=
og-=
Tildelingsoperatorer - https://stackoverflow.com/questions/542995
-
https://stackoverflow.com/questions/7140158
- https://stackoverflow.com/questions/1968371
-
Svar nedenfor
- https://stackoverflow.com/questions/2202331
-
https://stackoverflow.com/questions/1241432
- https://stackoverflow.com/questions/1466408
-
https://stackoverflow.com/questions/6484968
- https://stackoverflow.com/questions/1466408
,
Variabeldeklarationer -
https://stackoverflow.com/questions/41383218
- https://stackoverflow.com/questions/2715654
- https://stackoverflow.com/questions/4169882
-
https://stackoverflow.com/questions/4891872
` `
`` Udførelsesoperator -
https://stackoverflow.com/questions/6002296
<?=
Korte åbne tags - https://stackoverflow.com/questions/1963901
- https://stackoverflow.com/questions/2020445
-
https://stackoverflow.com/questions/1959256/what-does-mean
[]
Arrays (kort syntaks siden PHP 5.4) - https://stackoverflow.com/q/20709055/2758197
- https://stackoverflow.com/questions/6933345
- https://stackoverflow.com/questions/2431629
- https://stackoverflow.com/questions/3908576
-
[Shorthand for arrays: bogstavelig
$var = []
tomt array] (https://stackoverflow.com/questions/4271874) -
https://stackoverflow.com/questions/200640
...
Udpakning af argumenter (siden PHP 5.6)**
Eksponering (siden PHP 5.6) -
Kan jeg bruge hashes til kommentarer i PHP?
-
php-metodeargumenttyper med spørgsmålstegn (?type)
Operatorer til forøgelse/formindskelse
++
inkrementeringsoperator--
dekrementeringsoperatorDisse kan gå før eller efter variablen.
Hvis de sættes før variablen, foretages forhøjelsen/nedsættelsen af variablen først og derefter returneres resultatet. Hvis de sættes efter variablen, returneres variablen først, hvorefter der foretages en inkrementering/decrementering af variablen.
F.eks:
Levende eksempel
I ovenstående tilfælde anvendes
++$i
, da det er hurtigere.$i++
ville give de samme resultater.Pre-increment er en smule hurtigere, fordi den virkelig øger variablen og derefter 'returnerer' resultatet. Post-increment opretter en særlig variabel, kopierer værdien af den første variabel dertil og erstatter først efter at den første variabel er brugt, dens værdi med den anden variabel.
Du skal dog bruge
$apples--
, da du først vil vise det aktuelle antal æbler, og næst vil du trække en fra det.Du kan også inkremere bogstaver i PHP:
Når
z
er nået, eraa
den næste, og så videre.Stack Overflow-indlæg:
Bitvis operatør
Hvad er en bit? En bit er en repræsentation af 1 eller 0. I princippet OFF(0) og ON(1).
Hvad er en byte? En byte består af 8 bits, og den højeste værdi af en byte er 255, hvilket vil sige, at alle bits er sat. Vi vil se på, hvorfor den højeste værdi for en byte er 255.
Denne repræsentation af 1 byte
1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 = 255 (1 byte)
Et par eksempler til bedre forståelse
Operatoren "AND":
&
Dette ville give tallet 8. Hvorfor? Lad os se det ved hjælp af vores tabeleksempel.
Så du kan se i tabellen, at den eneste bit, de deler sammen, er den 8 bit.
Det andet eksempel
De to delte bits er 32 og 4, og når de lægges sammen giver det 36.
Operatoren "Or": |
Dette ville give nummer 11. Hvorfor?
Du vil bemærke, at vi har 3 bits indstillet i kolonnerne 8, 2 og 1. Læg dem sammen: 8+2+1=11.