|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
RE: mysql?
Try:
// adding more data to array $_SESSION['test2']["c"] = "3"; $_SESSION['test2']["d"] = "4"; |
|
#3
|
|||
|
|||
|
RE: associative arrays
Thanks very much. It worked!
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > associative arrays |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|