associative array php using array notation code example

Example 1: how to create associative array in php

<?php 
  /*
  there are three type of array
  	1 - Indexed array
  */
 	$a = array('a','b','c');
	$b = ['a','b','c'];
	/*
    2 - Associative array
    */
	$c = array(
    	'keyOne'=>'valueOne',
      	'keyTwo'=>'valueTwo'
    );
	$d = [
      'keyOne'=>'valueOne',
      'keyTwo'=>'valueTwo'
    ];
/*
    3 - Multidimensional  array
    */
	$c = array(
    	'keyOne'=>array('a','b','c'),
      	'keyTwo'=>array('a'=>'1','b'=>'2')
    );
	$d = [
      'keyOne'=>['a','b','c'],
      	'keyTwo'=>['a'=>'1','b'=>'2']
    ];
  ?>

Example 2: php associative array

Array
(
    [email] => abeermanchanda00@gmail.com
    [password1] => chess
    [passcheck1] => on
    [submit] => Login
)

Tags:

Php Example