Go Back   Site Owners Forums - Webmaster Forums > Web Programming > Programming General > PHP / mySQL

Notices


Reply
 
Thread Tools Rate Thread Display Modes
Old 08-01-2013, 01:09 PM   #1
noahwilson
Registered User
 
Join Date: Mar 2013
Posts: 246
How to use associative array in php?

Hello Guys
How to use associative array in php? please let me help and share you suggestion.
Thanks.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
noahwilson is offline   Reply With Quote

Old 11-05-2013, 11:49 PM   #2
mridul
Registered User
 
Join Date: Sep 2013
Posts: 92
<?php
$cars=array("Volvo","BMW","Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>

and you will get output like this:-
$cars1="Volvo";
$cars2="BMW";
$cars3="Toyota";
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
mridul is offline   Reply With Quote
Old 12-18-2013, 05:38 AM   #3
lampdev112
Registered User
 
Join Date: Dec 2013
Posts: 30
Creating Associative Arrays gives you a good way to use labels as the key in the array items instead of using numbered keys that increment automatically. This way you can use a word that has meaning to you as key.

This is how we create an Associative Array holding item names(labels) and their prices:
<?php
// create an associative array that is a cart holding items and prices
$cart_array = array(
"cereal" => "5.00",
"coffee beans" => "2.50",
"bananas" => "3.50",
"onion" => "1.00",
"lettuce" => "2.40",
"tomato" => "1.00",
);
// and here is how you can output any key's value you choose
echo "Bananas cost $" . $cart_array["bananas"] . " at this store.";
echo "<br /><br />";
// And here is how you can print the whole array for viewing and debugging
print_r($cart_array);
?>
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
lampdev112 is offline   Reply With Quote
Old 01-02-2014, 12:14 AM   #4
Die_heart
Registered User
 
Join Date: Nov 2013
Location: Surat
Posts: 971
<?php
// create an associative array that is a cart holding items and prices
$cart_array = array(
"cereal" => "5.00",
"coffee beans" => "2.50",
"bananas" => "3.50",
"onion" => "1.00",
"lettuce" => "2.40",
"tomato" => "1.00",
);
// and here is how you can output any key's value you choose
echo "Bananas cost $" . $cart_array["bananas"] . " at this store.";
echo "<br /><br />";
// And here is how you can print the whole array for viewing and debugging
print_r($cart_array);
?>
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
Die_heart is offline   Reply With Quote
Old 01-13-2014, 10:09 PM   #5
MichaelHolloman
Registered User
 
Join Date: Dec 2013
Posts: 21
Associative arrays use named keys that you assign to them. For example:
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
echo "Peter is " . $age['Peter'] . " years old.";
?>
You can also use a loop through associated array.
To get any assistance related to IT support you can contact with Network Fish London. They will provide you excellent Tech Support.
MichaelHolloman is offline   Reply With Quote
Old 01-16-2014, 11:06 PM   #6
Luca tall
Registered User
 
Join Date: Apr 2013
Location: Chennai
Posts: 72
Examples of Associative array:
<?php

$course = array ("C++"=>"Rs.1400", "Java"=>"Rs.1600","PHP"=>"Rs.2400","Netwoking"=>"R s.3000");
echo "c++ course is" .$course['C++'];
?>

Here key= C++ = Rs 1400.
Key can either be integer or a string.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
Luca tall is offline   Reply With Quote
Old 03-17-2014, 02:49 AM   #7
alligatortek001
Registered User
 
Join Date: Nov 2013
Posts: 92
// create an associative array that is a cart holding items and prices
$cart_array = array(
"cereal" => "5.00",
"coffee beans" => "2.50",
"bananas" => "3.50",
"onion" => "1.00",
"lettuce" => "2.40",
"tomato" => "1.00",
);
// and here is how you can output any key's value you choose
echo "Bananas cost $" . $cart_array["bananas"] . " at this store.";
echo "<br /><br />";
// And here is how you can print the whole array for viewing and debugging
print_r($cart_array);
?>
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
alligatortek001 is offline   Reply With Quote
Old 04-15-2014, 03:28 AM   #8
tomsmith
Registered User
 
Join Date: Apr 2014
Posts: 1
<?php
// create an associative array that is a cart holding items and prices
$cart_array = array(
"cereal" => "5.00",
"coffee beans" => "2.50",
"bananas" => "3.50",
"onion" => "1.00",
"lettuce" => "2.40",
"tomato" => "1.00",
);
// and here is how you can output any key's value you choose
echo "Bananas cost $" . $cart_array["bananas"] . " at this store.";
echo "<br /><br />";
// And here is how you can print the whole array for viewing and debugging
print_r($cart_array);
?>
check this code and reply with output http://tutorialterminal.blogspot.in/

Last edited by tomsmith; 04-15-2014 at 03:28 AM.. Reason: site is missing
tomsmith is offline   Reply With Quote
Old 05-26-2014, 08:56 PM   #9
kevinkrieger
Registered User
 
Join Date: Jan 2014
Posts: 104
<?php
$array = array(
"foo" => "bar",
42 => 24,
"multi" => array(
"dimensional" => array(
"array" => "foo"
)
)
);

var_dump($array["foo"]);
var_dump($array[42]);
var_dump($array["multi"]["dimensional"]["array"]);
?>
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
kevinkrieger is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Importance of Php Development for Web Development tech.biztech Programming General 35 11-22-2019 12:37 AM
PHP introduction stevepatton PHP / mySQL 48 06-17-2019 02:02 AM
PHP project training in ahmedabad, live project training in php ahmedabad anantitsolution Post your ad here 1 07-16-2013 07:42 PM
The best source of learn PHP easily at home. chikkiarora Programming General 11 02-10-2013 02:18 AM
Are you aware of the fact that PHP programming is the most widely used one? johnrichards774 PHP / mySQL 3 02-07-2012 05:41 AM


All times are GMT -7. The time now is 06:48 AM.


Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.