Menu
CoddyTech
Course

Luau for PHP Developers

Transfer PHP arrays, closures and classes to Luau tables and typed signatures. Practice truth rules, runtime validation, relative modules and metatable objects, build a stock ledger and port two PHP programs.

PHP and Luau side by side

The same program in PHP and in Luau, from the lessons of this course.

  1. Print and Comment

    PHP echo accepts multiple expressions and adds no newline automatically; dot concatenates strings. Luau print adds a newline and tabs between arguments. Use .. to construct one exact string, and let the task driver print returned results. Luau comments begin…

    PHP
    1<?php2$name="Ada"; echo "Hi ".$name," !","\n";
    Luau
    1local name = "Ada"2print(`Hi, {name}`)
  2. Missing Fields and Optionals

    PHP arrays can retain a key mapped to null. array_key_exists distinguishes presence, while isset treats null like absence. Luau nil removes the association. An optional type annotation cannot preserve a nil-valued field; use a tagged record when…

    PHP
    1<?php2$values=["x"=>null]; echo (array_key_exists("x",$values) ? "true":"false"),"\n";
    Luau
    1local d = {x = nil}2print(d.x == nil)
  3. Inclusive Numeric Loops

    PHP counted loops often use an exclusive upper bound, while range includes endpoints. Luau numeric for includes its final bound and accepts an optional step. Translate the actual visited values and empty cases instead of copying the source endpoint unchanged.

    PHP
    1<?php2$total=0;for($n=2;$n<5;$n++){$total+=$n;}echo $total,"\n";
    Luau
    1local total = 02for i = 1, 3 do total = total + i end3print(total)
  4. Functions and Returns

    PHP functions may declare parameter and return types and can explicitly accept arguments by reference. Luau numeric rebinding stays local, while tables allow shared field mutation. Annotations describe intent but this runner does not analyze types. Validate…

    PHP
    1<?php2function hours(int $total):int{return intdiv($total,60);}echo hours(125),"\n";
    Luau
    1local function twice(x: number): number return x * 2 end2print(twice(4))
  5. Lists as Dense Tables

    PHP arrays are ordered maps, with array_splice closing numeric-key gaps while unset removes a key without shifting. Luau dense sequences use one-based keys and table.remove shifts later values. Assigning nil creates a hole, and length is not a general…

    PHP
    1<?php2$values=[10,20,30];array_splice($values,1,1);echo implode(",",$values),"\n";
    Luau
    1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))
  6. Sorting and Comparators

    PHP sorting functions mutate arrays, with key preservation depending on the function and success returned separately. Luau table.sort mutates a sequence, returns no sequence and expects a Boolean ordering predicate. PHP three-way comparison results cannot be…

    PHP
    1<?php2$a=[10,2];$b=$a;sort($b,SORT_NUMERIC);echo implode(",",$a),"\n",implode(",",$b),"\n";
    Luau
    1local a={3,1,2}2table.sort(a)3print(a[1])

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

Final Source Ports

2 lessons

More courses for PHP developers

Learn Luau from another language

Frequently asked questions

Who is Luau for PHP Developers for?

For people who already write PHP and want to learn Luau. Each lesson starts from PHP you know and shows how Luau does the same thing, so you skip the beginner basics.

Do I need to know Luau already?

No. The course starts with your first Luau program. You need PHP basics: variables, conditions, loops, functions and collections.

How many lessons does Luau for PHP Developers have?

Luau for PHP Developers contains 48 interactive lessons you can complete at your own pace.

What does Luau for PHP Developers cover?

The course is organized into chapters covering: First Luau Programs, Values and Decisions, Iteration and Flow, Functions and Closures, and more.

Is Luau 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.

Coddy programming languages illustration

Start Luau for PHP Developers for free

Get started