<?php
echo date("Y/m/d") . "<br />";
echo date("Y.m.d") . "<br />";
echo date("Y:->m:->d")."<br>";
echo("hello") ."<br/>";
 $app5=5;
echo($app5);
$baby="going";
echo("$baby i love to ");
//echo ($baby$app5);
if($app5==5)
echo "dance"."<br>";
echo strlen("dance");
echo strpos("dance","h");
switch($ab=1)
{
	case 1:
		echo 1;
	case 2:
		echo 2;
		default :
		echo "default";
}
$a = array(1,2,5,3,6);
for($i=0;$i<5;$i++)
echo $a[$i]."<br>";
$a = array(1=>"apple",2=>"boy",3=>"girl",4=>"koel",5=>"good");
for($i=1;$i<=5;$i++)
echo $a[$i]."<br>";
echo $a[2]."<br>";
echo $a['2']."<br>";
$a=array	(

$0=array(40,60,20),
$1=array(278,102,173)
);
for($i=0;$i<2;$i++)
{	echo "<br>".$a[$i];
	for($j=0;$j<3;$j++)
	echo $a[$i][$j]." ";
}
?>

I have started learning PHP today and I was trying out some very basic commands.
I am getting an error in line 35.
How to use 2-d arrays in PHP?
Also give example of Associated 2-d array.
Any help will be appreciated.

A variable cannot start with a number, you have to use an alphabetic character instead, so $0 and $1 are wrong. For example use $a0 and $a1.

Anyway, in your case a bi-dimensional array can be written as below:

$a = array(
 array(40,60,20),
 array(278,102,173)
);

To display data, then write:

echo $a[0][1]; # will display 60

If you want to assign specific keys you can write:

$a = array(
'alfa' => array(40,60,20),
'beta' => array(278,102,173)
);

echo $a['alfa'][2]; # output 20

bye.

commented: Nicely explained +5
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.