PHP
Learn PHP by typing modern, idiomatic code.
Type through modern PHP: associative arrays, the array_* functions, classes and traits, typed properties, and arrow functions. Each snippet is idiomatic, current PHP, and an AI tutor explains every line — how an associative array doubles as a map, why type declarations catch bugs early — so you learn today's PHP, not the tutorials from a decade ago.
Progress0 / 690 solved · 0/50 sections
best wpm
0
avg wpm
0
accuracy
0%
runs
0
level
1
rating
1000
Run PHP on your machine
1. Install the toolchain
brew install php # or: sudo apt install php-cli2. Save your code as hello.php, then compile & run
php hello.phpprogress by section
2Strings In Depth0/18start →
Concatenate with .Change caseNeedle-in-haystack testsSplit with explodeJoin with implodeIndex a stringString interpolationRepeat a stringTrim whitespaceByte vs character lengthFormat numbersPad to a widthReplace with str_replaceSplit into charactersFind a positionSubstrings with substrHeredoc and nowdocFormat with sprintf
3Values & References0/16start →
Arrays copy on assignReference variablesArrays pass by valueClone an objectforeach by referenceLoose equality ==Objects share a handleObjects are mutable in calleesPass an array by referencePass a scalar by referenceStrict equality ===Comparing objectsObject identitySwap via referencesDeep clone with __cloneThe dangling foreach ref
4Slices & Arrays0/17Unlock →
5Data structures0/11Unlock →
6Iterators0/20Unlock →
Sum, product, countChain arraysIndex with the keyarray_filterarray_mapSkip and takeStep and reversefilter then mapFold with a seedPartitionReduce without a seedany / all / findZip two arraysArrayIterator & array_walkFlatten nested arraysA generatorMin and max by keyRunning totalsyield fromThe Iterator interface
7Traits0/21Unlock →
Trait and useInterface and implementsCountableInterface constants__invokeComposing traitsSpaceship operator__toString and StringableAbstract method in a traitConflict: as aliasConstant in a trait__get and __setConflict: insteadofJsonSerializableMultiple interfacesStatic member in a traitSort by fieldsArrayAccessChange visibility with asIteratorAggregateIterator interface
8Generics0/20Unlock →
A generic containerDuck typingInterface as a boundThe mixed typeReturn a ClosureAn Either typeIntersection typesThe iterable typeGeneric over iterablesGeneric minInstantiate a class-stringA newtype wrapperA generic stackDocblock @templateUnion vs mixedCovariant return typesSplFixedArrayCallable key parameterA type tagTrait as a blanket
9Lifetimes0/20Unlock →
No manual freeScalars pass by valueArrow fn auto-captureClosure captures by value__destructglobal keywordNo block scopeObjects pass by handleObjects share a handleEnd-of-scope cleanupunset drops a referenceClosure captures by referenceClosures keep captures aliveReference variablesCleanup at shutdownStatic local variableReference cyclesWeakMapWeakReferenceBinding a closure
10Closures0/20Unlock →
A closureCapturing the environmentMultiple parametersTyped params & block bodyuse() by valueClosure as an argumentCallbacksCapturing in a filterFirst-class callableClosures drive the array functionsusort with a closureAn array of closuresCapture by referenceBy value vs by referenceCurryingReturning a closureA stateful closureClosure::bindHigher-order: composeReturn different closures
11Pattern Matching0/20Unlock →
Literals and defaultDestructure by keyDestructure a listmatch as an expressionMatch a nullableSeveral values per armmatch(true) for rangesSwap by destructuringswitch with fallthroughLoop while a value is presentMatch an enumDestructure in foreachGuards via match(true)instanceof dispatchNested destructuringSkip positionsmatch is strictEnum method with matchMatch a result typeRecursive structure
12Error Handling0/21Unlock →
try / catchgetMessage and getCodethrow an exceptionContext in messagesCustom exception classDivisionByZeroErrorfinally for cleanupModulo by zeroCatch several typesException with attributesException with a getterfinally runs before returnException hierarchyOrdered handlersRe-throwCatch ThrowableTypeError under strict typesCollect the successesgetPreviousChaining a previous errorthrow as an expression
13Option & Result0/21Unlock →
Null coalescing ??Default parametersemptyTest for nullissetnull for absenceRead with a defaultNull coalescing assignment ??=Coalesce chainElvis operator ?:Nullable return typeMap with a ternaryarray_key_exists vs issetDrop the nullsTransform if presentNull-safe operator ?->Chained ?->Result as a tupleCoalesce or throwA Result classCombine two optionals
14Conversions0/16Unlock →
15Collection Conversions0/19Unlock →
16Math0/14Unlock →
17Encoding0/22Unlock →
ord and chrString to bytesASCII checks and caseBase64 encode and decodeHex encode and decodeBytes to stringBase conversions of intsROT13URL decodeURL encodeConvert between basesList code pointsHex encode by handBytes vs charactersUnicode code pointsBig-endian bytesLittle-endian bytesParse a number in a baseURL-safe base64Caesar cipherPack a headerXOR cipher
18Random0/20Unlock →
Secure random integerCoin flipMersenne TwisterPick a random elementRandom bytesRandom hex tokenSeed the generatorShuffle in placeWeighted true/falseRoll many diceRandom enum casePassword generatorFloat in a rangeReproducible sequencesSample without replacementRandom alphanumeric stringFloat in [0, 1)Weighted choiceUUID v4Normal distribution
19Data I/O0/18Unlock →
Parse CSV into rowsDecode from JSONEncode to JSONTab-separated valuesBuild CSV by joiningSelect one columnCSV into a number matrixHeader plus rowsWhitespace matrixRecords to CSV linesSkip blanks and commentsAligned tableMatrix as textBuild CSV with fputcsvParse key=value configQuoted CSV fieldsJSON round-tripDrop unparseable rows
20Linear Algebra0/21Unlock →
21Text Processing0/16Unlock →
22Date & Time0/12Unlock →
23Memory0/13Unlock →
24Modules0/21Unlock →
A namespaceA namespaced constantAn internal helperSub-namespacesuse as (alias)use a classA class in a namespaceNamespaced configAn enum in a namespaceFully-qualified namesGlobal fallbackGrouped useuse constuse functionA small utility namespacePrivate field, public getterAn interface in a namespacenamespace\ relative pathFlatten a deep pathReach a sibling namespacespl_autoload_register
25Macros0/20Unlock →
call_user_funccompact()Dynamic property nameextract()func_get_args__toStringVariadic arguments__call magic methodcall_user_func_arrayDynamic method dispatch__get magic property__invoke__set magic propertyVariable variables__callStatic__isset and __unsetReflectionClassReflectionMethod invokeAttributes + reflectionClosure::bind
26Testing0/21Unlock →
PHPUnit vs the stdlibA tiny assert_equalPHP's assert()assert_trueMultiple testsassert_not_equalTesting string outputTesting a truth tableAsserting on an arrayAsserting a countA pass/fail counterTesting a methodTesting a nullable resultA shared fixtureassert_close helperA data providerAssert the exception typeAssert on the messageComparing floatsTable-driven testsassert_throws
27Algorithms0/9Unlock →
28Sorting Algorithms0/12Unlock →
29Expression Parsing0/6Unlock →
30Idioms0/9Unlock →
31OOP & Traits0/8Unlock →
32Trait Objects0/15Unlock →
Branch with instanceofDispatch through an interfaceinstanceof and is_aAn abstract-base collectionArray of implementersDefault method on a baseDynamic dispatchReturn one of several typesResolve a method by nameMixed types, one methodA pipeline of closuresA callable registryEnum implements an interfaceFirst-class callablesStrategy pattern
33Design Patterns0/14Unlock →
35File I/O0/6Unlock →
36Filesystem0/18Unlock →
37Networking0/16Unlock →
Build a query stringResolve a hostnameRoute by pathValidate an IP addressParse a URLParse an HTTP request lineReverse DNSfsockopen clientBuild an HTTP responseBind an ephemeral portShut down a connectionRead timeoutUDP send and receiveAccept with stream_selectTCP client and serverA minimal HTTP server
38Concurrency0/7Unlock →
39Unsafe & FFI0/14Unlock →
40Commands0/14Unlock →
41Array0/10Unlock →
43String0/10Unlock →
45Interval0/5Unlock →
46Linked List0/6Unlock →
47Tree0/14Unlock →
Maximum Depth of Binary TreeInvert Binary TreeSame TreeLowest Common Ancestor of a BSTBinary Tree Level Order TraversalSubtree of Another TreeKth Smallest Element in a BSTValidate Binary Search TreeImplement Trie (Prefix Tree)Construct Binary Tree from Preorder and InorderAdd and Search WordBinary Tree Maximum Path SumSerialize and Deserialize Binary TreeWord Search II