Menu
CoddyTech
Course

PHP for C Developers

Transfer your C experience to PHP 8.3: values, control flow, arrays, functions, exceptions and object design. Build a multi-file time ledger with validated parsing and deterministic reports.

C and PHP side by side

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

  1. Modules and first run

    C compiles translation units and begins execution at main. PHP executes an entry script and loads declarations with require_once. PHP files require an opening tag, and __DIR__ anchors module paths. The course uses CLI input and output rather than a web…

    C
    1#include <stdio.h>2
    3int main(void) {4puts("hello CLI");5return 0;6}
    PHP
    1<?php2declare(strict_types=1);3echo "hello CLI\n";
  2. Branches and precedence

    C and PHP both provide braces, &&, || and conditional selection with ?:. PHP additionally has low-precedence and/or operators with different grouping from && and ||. Preserve parentheses and every bound instead of assuming similar spellings imply the same…

    C
    1#include <stdio.h>2
    3int main(void)4{5    int n = 10;6    if (0 <= n && n <= 10) {7        puts("in");8    } else {9        puts("out");10    }11    return 0;12}
    PHP
    1<?php2declare(strict_types=1);3$n=4; echo $n>3?"high":"low"; echo "\n";
  3. Lists are PHP arrays

    A C array has fixed storage and positional indexes; removing an item requires a logical length change and often shifting. PHP arrays are ordered maps. unset removes a key without renumbering, so use array_values when a dense list is required by comparison or…

    C
    1#include <stddef.h>2#include <stdio.h>3int main(void) {4    const char *items[] = {"a", "b", "c"};5    size_t length = sizeof items / sizeof items[0];6    for (size_t i = 1; i + 1 < length; ++i) {7        items[i] = items[i + 1];8    }9    --length;10    for (size_t i = 0; i < length; ++i) {11        printf("%s%s", i == 0 ? "" : ",", items[i]);12    }13    putchar('\n');14    return 0;15}
    PHP
    1<?php2declare(strict_types=1);3$a=[10,20,30]; unset($a[1]); echo implode(",",array_keys($a)),"\n";
  4. Functions and return types

    C prototypes check compatible argument and result types during compilation, with conversions following C rules. PHP parameter and return declarations are runtime contracts. strict_types belongs to the caller for scalar arguments, and an array declaration does…

    C
    1#include <stdio.h>2static int twice(int x) {3    return x * 2;4}5int main(void) {6    printf("%d\n", twice(4));7    return 0;8}
    PHP
    1<?php2declare(strict_types=1);3function surround(string $s):string{return "(".$s.")";} echo surround("note"),"\n";
  5. Exceptions and state

    C commonly returns a status and writes successful results through output pointers; it has no built-in exception or finally syntax. PHP throws and catches exceptions and can run cleanup in finally. Validate before mutation so expected rejection preserves the…

    C
    1#include <stdbool.h>2#include <stdio.h>3static bool double_nonnegative(int value, int *result) {4    if (value < 0) {5        return false;6    }7    *result = value * 2;8    return true;9}10int main(void) {11    int result = 0;12    if (!double_nonnegative(-1, &result)) {13        puts("caught");14    } else {15        printf("%d\n", result);16    }17    return 0;18}
    PHP
    1<?php2declare(strict_types=1);3try {throw new RuntimeException("bad");} catch(RuntimeException $e){echo "caught";} finally{echo ":done\n";}
  6. Classes and typed properties

    C structs have declared fields and require deliberate initialization according to storage duration. PHP class properties can have declared types, but a typed property without initialization cannot be read safely. Allocate independent objects and initialize…

    C
    1#include <stdio.h>2struct Item { int n; };3static struct Item item_new(int n)4{5    struct Item item = {n};6    return item;7}8int main(void)9{10    struct Item a = item_new(2);11    struct Item b = item_new(5);12    a.n = 8;13    printf("%d:%d\n", a.n, b.n);14    return 0;15}
    PHP
    1<?php2declare(strict_types=1);3class Flag {public bool $enabled=false;} $f=new Flag(); echo $f->enabled?"on\n":"off\n";

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for C developers

Learn PHP from another language

Frequently asked questions

Who is PHP for C Developers for?

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

Do I need to know PHP already?

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

How many lessons does PHP for C Developers have?

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

What does PHP for C Developers cover?

The course is organized into chapters covering: Values and output, Control flow, Collections, Functions and modules, and more.

Is PHP for C 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 PHP for C Developers for free

Get started