Four Flavors of Associative Arrays

A guy in a blue shirt speaking.

When it comes to programming, there are a lot of different ways to accomplish the same task. Here are four different ways to create associative arrays in PHP, C# and JavaScript:

PHP Array Method (this is very common in PHP):

$user = array();
$user[“name”] = “John Smith”;
$user[“email”] = “”;

PHP Custom Built Object:

class User
public $name;
public $email;

$user = new User();
$user->name = “John”;
$user->email = “”;

C# Built in Generic Type – Dictionary:

Dictionary user = new Dictionary<string, string>();
user.Add(“name”, “John”);
user.Add(“email”, “”);

JavaScript Standard Associative Array w/ Array.push() method:

var user = [];
name: “John”,
email: “”

Leave a Reply

Your email address will not be published. Required fields are marked *