PHP to JavaScript

This tutorial provides information on passing data from server side to client side, from PHP to JavaScript. We cover basic techniques for outputting simple data types and arrays as well as the use of JSON (JavaScript Object Notation) for transmitting more complex data types between PHP and JavaScript.

Passing Scalar Values
How to pass strings, numbers, and booleans from PHP to JavaScript.
Passing Scalar Values Using json_encode
How to use PHP's json_encode function to pass strings, numbers, and booleans to JavaScript.
Passing Basic Arrays
How to use PHP's implode function to pass single-level arrays to JavaScript.
JavaScript Object Notation
JavaScript Object Notation (JSON): what it is, what data types it supports, and how it can be used. JSON's browser support and PHP language support.
Passing Arrays to JSON and JavaScript
How to use PHP's json_encode function to pass single-level and multi-dimensional arrays to JSON strings and JavaScript.
JavaScript's JSON.parse
How to use JSON.parse to parse JSON strings, including output from json_encode.
Using a Reviver Function with JSON.parse
How to screen and modify JSON.parse results.

Download Examples

A download file provides this tutorial's examples free of charge. Donations are appreciated!