×
×
PHP Tutorial
What is PHP Environment Setup of PHP PHP Syntax PHP Comments PHP Echo & print PHP Variables PHP Scope Variables PHP $ and $$ Variable PHP Constants PHP Operators PHP Data TypesPHP Conditional Statements
PHP Loop Type
PHP Arrays
PHP String PHP FunctionsPHP Form Examples
Form Intro Get & Post Form Validation / Required PHP Complete FormPHP Advanced
PHP Include / Require PHP Date & Time PHP Session PHP Cookies PHP File Handling PHP Open File PHP Read File PHP Write File PHP Append File PHP Delete File PHP File Upload PHP Sending Mail PHP Error HandlingAssociative Arrays
An associative array is a type of array where the key has its own value. In an associative array, we make use of key
and value
.
There are two ways to create an associative array:
Example 1:
<?php
$age = array("Kailash"=>"27", "Ranjeet"=>"37", "Hemant"=>"43");
echo "Kailash is " . $age['Kailash'] . " years old.";
?>
Output:
Kailash is 27 years old.
Example 2:
<?php
$salary=array("Kailash"=>"350000","Ranjeet"=>"450000","Hemant"=>"200000");
echo "Kailash salary: ".$salary["Kailash"]."<br/>";
echo "Ranjeet salary: ".$salary["Ranjeet"]."<br/>";
echo "Hemant salary: ".$salary["Hemant"]."<br/>";
?>
Output:
Kailash salary: 350000
Ranjeet salary: 450000
Hemant salary: 200000
Elevenstech Web Tutorials
Elevenstech Web Tutorials helps you learn coding skills and enhance your skills you want.
As part of Elevenstech's Blog, Elevenstech Web Tutorials contributes to our mission of “helping people learn coding online”.
Read More
Newsletter
Subscribe to get the latest updates from Elevenstech Web Tutorials and stay up to date
Copyright 2018 - 2024 Elevenstech Web Tutorials All rights reserved.