PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old July 9th, 2002, 03:18 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
associative arrays

Snippit:

<?php

session_start();

// declaring the array
$test1 = array('a' => 1, 'b' => 2);

// adding more data to array
$test1["c"] = "3";
$test1["d"] = "4";

// print out the contents of the array
echo "<br />Sample of associative array test1<br />";
foreach($test1 as $key => $value) {
echo "<br />$key = $value";
}

echo "<br /><br /><br /><hr /><br />";

// example of _SESSION (superglobal) PhP 4.1 >
// reference link
echo "<a href="http://www.php.net/manual/en/ref.session.php">Reference link</a>";
$_SESSION['test2'] = array('a' => 1, 'b' => 2);

// adding more data to array
$_SESSION['test2["c"]'] = "3";
$_SESSION['test2["d"]'] = "4";

// print out the contents of the array
echo "<br />Sample of associative array with _SESSION test2<br />";
foreach($_SESSION['test2'] as $key => $value) {
echo "<br />$key = $value";
}

session_destroy();


?>


Sample output:

Sample of associative array test1

a = 1
b = 2
c = 3
d = 4



--------------------------------------------------------------------------------

<a href=http://www.php.net/manual/en/ref.session.php

Sample of associative array with _SESSION test2

a = 1
b = 2


Question: what am I doing wrong when appending extra fields for the test2 associative array and as a SESSION variable?

Thanks.

Reply With Quote
  #2  
Old July 9th, 2002, 01:23 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: mysql?

Try:

// adding more data to array
$_SESSION['test2']["c"] = "3";
$_SESSION['test2']["d"] = "4";

Reply With Quote
  #3  
Old July 9th, 2002, 02:45 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: associative arrays

Thanks very much. It worked!

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > associative arrays


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway