Show Menu
Cheatography

PHP - Arrays Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Decl­aring an Array (two ways)

$car_­makes = array(­"­For­d", "­VW", "­Saa­b");
$car_­models = ["Fo­cus­", "­Jet­ta", "­Mia­ta"];

Indexed Array

$car_­models = ["Fo­cus­", "­Jet­ta", "­Mia­ta"];
$car_­mod­els[1] // returns "­Jet­ta"

Asso­c­iative Array

$car_­models = [
  "­mod­el" => "Volkswagen", 
  "make"­ => "Passat", 
  "year" => 2013
];

$car_­mod­els["make"] // returns "Passat"