R for PHP Developers
Move from PHP to base R: vectors, missing values, data frames, functions, S3 dispatch, S4 validity and closure state. Build a connected multi-file basket and port a stock ledger.
PHP and R side by side
The same program in PHP and in R, from the lessons of this course.
Text and Output
PHP echo writes its operands without an automatic newline, and the dot operator concatenates strings. R cat also needs explicit separators and a final newline; paste and paste0 construct strings. Rscript runs an entry file and source evaluates supporting…
PHP1<?php2$name="Ada"; echo "Hi ".$name," !","\n";R1ready <- 32cat(paste0("Ready: ", ready), "\n", sep="")Comparisons and Recycling
PHP array === compares keys and values with matching types and order, while object === tests identity. R == is elementwise and may recycle shorter operands. Use all for a reduced decision or identical when values, storage types and attributes belong to…
PHP1<?php2$a=[1];$b=[1];echo ($a===$b ? "true":"false"),"\n";R1cat(identical(1L, 1), all(c(2, 3) == c(2, 3)), "\n")Vector Subsetting
PHP dense list literals start at zero, but arrays may also have explicit negative integer keys; those keys are not end-relative indexing. R positive indexes start at one, zero selects nothing and negative indexes exclude positions. Do not translate array keys…
PHP1<?php2$values=[4,8,12];echo $values[count($values)-1],"\n";R1values <- c(4, 8, 12)2cat(paste(values[-1], collapse=" "), "\n", sep="")Typed Iteration
PHP array_map applies a callback and produces an array without imposing a single result type. R lapply returns a list, sapply attempts simplification and vapply checks each result against a type-and-length prototype. Choose the expected result shape…
PHP1<?php2$lengths=array_map(fn($word)=>strlen($word),["a","tea"]);echo implode(":",$lengths),"\n";R1words <- c("a", "tea")2sizes <- vapply(words, nchar, integer(1), USE.NAMES=FALSE)3cat(paste(sizes, collapse=" "), "\n", sep="")Functions and Returns
PHP ordinary functions use return to produce a value and otherwise yield null; arrow functions return their single expression. R returns its last evaluated expression by default and offers return for early exit. R also uses lazy argument promises. Source…
PHP1<?php2function hours(int $total):int{return intdiv($total,60);}echo hours(125),"\n";R1is_long <- function(text) nchar(text)>42cat(is_long("coffee"), "\n", sep="")String Parsing
PHP preg_match uses regular expressions and filter_var can validate integer text, with false requiring a strict check so zero remains valid. R trimws and strsplit operate on character vectors; strsplit returns a list of token vectors. Choose fixed or regex…
PHP1<?php2preg_match("/^[a-z]+:([0-9]+)$/D","tag:42",$matches);echo $matches[1],"\n";R1parts <- strsplit("tea,cake", ",", fixed=TRUE)[[1]]2cat(length(parts), "\n", sep="")
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFiles and Atomic Values
6 lessonsLogic and Iteration
6 lessonsCollections and Ownership
5 lessonsData and Transformations
4 lessonsFunctions and Closures
5 lessonsParsing and S3 Dispatch
5 lessonsObjects and Invariants
6 lessonsCollaboration and Contracts
5 lessonsProject: Basket
4 lessonsFinal Challenges
2 lessonsFrequently asked questions
Who is R for PHP Developers for?
For people who already write PHP and want to learn R. Each lesson starts from PHP you know and shows how R does the same thing, so you skip the beginner basics.
Do I need to know R already?
No. The course starts with your first R program. You need PHP basics: variables, conditions, loops, functions and collections.
How many lessons does R for PHP Developers have?
R for PHP Developers contains 48 interactive lessons you can complete at your own pace.
What does R for PHP Developers cover?
The course is organized into chapters covering: Files and Atomic Values, Logic and Iteration, Collections and Ownership, Data and Transformations, and more.
Is R 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.