Kotlin for PHP Developers
Move from PHP to Kotlin through null safety, collection ownership, functions, properties and object contracts. Compare array ownership and closure captures, build an order processor, and port a stock ledger.
PHP and Kotlin side by side
The same program in PHP and in Kotlin, from the lessons of this course.
Strings and Templates
PHP double-quoted strings interpolate variables, while single-quoted strings largely preserve literal text. Kotlin string templates use dollar-prefixed names or braced expressions. PHP echo adds no newline automatically; Kotlin println does. PHP strings are…
PHP1<?php2$name="Ada"; echo "Hi ".$name," !","\n";Kotlin1fun main(){2val ready=33println("Ready: $ready")4}Equality and Identity
PHP strict equality compares types and values, but for objects === means the same instance. Kotlin == invokes null-safe equals and === checks identity. Strings have content equality; ordinary classes default to identity unless they supply a value contract…
PHP1<?php2$a="ab";$b="a"."b";echo ($a===$b ? "true":"false"),"\n";Kotlin1fun main(){2val a=String(charArrayOf('t','e','a'))3val b=String(charArrayOf('t','e','a'))4println(a==b)5}Arrays and IntArray
PHP arrays are ordered maps that can grow and contain mixed values. Kotlin arrays have fixed size, checked zero-based indexes and declared element types. IntArray stores primitive integers on the JVM. Use last or lastIndex for the final position and a mutable…
PHP1<?php2$values=[2,4,6];echo $values[count($values)-1],"\n";Kotlin1fun main(){2val a=intArrayOf(4,8,12)3println(a.last())4}While, Break, and Continue
PHP and Kotlin both provide while, break and continue, but Kotlin requires Boolean conditions. PHP numbered break levels are not Kotlin syntax; Kotlin uses labels for selected nested-loop control. Advance a manual index before a possible continue and…
PHP1<?php2$n=3;while($n>1){$n--;}echo $n,"\n";Kotlin1fun main(){2val kept=mutableListOf<String>()3for(word in listOf("tea","","STOP","coffee")){if(word=="STOP")break;if(word.isEmpty())continue;kept.add(word)}4println(kept.joinToString(","))5}Top-level Functions
PHP and Kotlin both allow top-level functions, but Kotlin requires parameter types and a statically determined result type. Kotlin parameters are read-only bindings, and a non-Unit block body needs explicit returns. A function returns one value, which can be…
PHP1<?php2function hours(int $total):int{return intdiv($total,60);}echo hours(125),"\n";Kotlin1fun isLong(text:String):Boolean = text.length>42fun main(){3println(isLong("coffee"))4}Input and String Formatting
PHP CLI programs can read lines with fgets(STDIN); this Kotlin task supplies a driver that owns console input and output. Kotlin readlnOrNull represents EOF as null, and toInt requires a complete valid integer string. PHP integer casts can accept numeric…
PHP1<?php2$cents=305;echo sprintf("tea: %d.%02d",intdiv($cents,100),$cents%100),"\n";Kotlin1fun main(){2println(" tea ".trim().uppercase(java.util.Locale.ROOT))3}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsStarting Kotlin
6 lessonsValues and Decisions
5 lessonsCollections and Ownership
5 lessonsIteration and Transformations
5 lessonsFunctions and Callbacks
5 lessonsInput, Errors, and Files
5 lessonsClasses and State
6 lessonsComposition and Value Types
5 lessonsProject: Order Processing
4 lessonsFinal Challenges
2 lessonsFrequently asked questions
Who is Kotlin for PHP Developers for?
For people who already write PHP and want to learn Kotlin. Each lesson starts from PHP you know and shows how Kotlin does the same thing, so you skip the beginner basics.
Do I need to know Kotlin already?
No. The course starts with your first Kotlin program. You need PHP basics: variables, conditions, loops, functions and collections.
How many lessons does Kotlin for PHP Developers have?
Kotlin for PHP Developers contains 48 interactive lessons you can complete at your own pace.
What does Kotlin for PHP Developers cover?
The course is organized into chapters covering: Starting Kotlin, Values and Decisions, Collections and Ownership, Iteration and Transformations, and more.
Is Kotlin for PHP Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.