PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
iamler
Forum Newbie
Posts: 2 Joined: Wed Jun 25, 2003 5:57 am
Location: Thailand
Post
by iamler » Wed Jun 25, 2003 5:57 am
It always show Array Array Array Array.
Can any one help me???
Thank you....
Code: Select all
<?php
session_start();
$info = array("coffee", "brown", "caffeine");
$_SESSION[wow] = each ($info);
echo session_id();
echo "<br>";
echo session_encode();
echo "<br><br>";
if(isset($_SESSION[wow]))
{
echo "It registered: <br>";
while (list ($drink, $color, $power) = each ($_SESSION[wow]))
{
echo $_SESSION[wow]."<br>\n";
}
}
else
{
echo "It not registered";
}
?>mod_edit: added
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Jun 25, 2003 6:18 am
Let's start with a link to
http://php.net/each echo $_SESSION[wow]."<br>\n";
why do you
print the array ? You want the values.
Please read
http://www.php.net/manual/en/language.types.array.php#language.types.array.donts
maybe
foreach() is simpler to use
Code: Select all
<?php
session_start();
$_SESSION['wow'] = array();
$info = array('drink'=>'coffee', 'color'=>'brown', 'power'=>'caffeine');
$_SESSION['wow'][] = $info; // appending the array $info to $_SESSION['wow']
?><html>
<body>
<fieldset>
<legend>session_id</legend>
<?php echo session_id(); ?>
</fieldset>
<fieldset>
<legend>session_encode</legend>
<?php echo session_encode(); ?>
</fieldset>
<?php
if(isset($_SESSION['wow']))
{
?>
It registered: <br />
<pre><?php print_r($_SESSION['wow']); ?></pre>
<?php
foreach($_SESSION['wow'] as $wowEntry)
echo $wowEntry['drink'], ' - ', $wowEntry['color'], ' - ', $wowEntry['power'], '<br />';
}
else
{
echo "It not registered";
}
?>
</body>
</html>
pootergeist
Forum Contributor
Posts: 273 Joined: Thu Feb 27, 2003 7:22 am
Location: UK
Post
by pootergeist » Wed Jun 25, 2003 7:07 am
or you might like to try serialize - unserialize to place the array within a session variable
Code: Select all
$info = array('drink'=>'coffee', 'color'=>'brown', 'power'=>'caffeine');
$_SESSION['wow'] = serialize($info); // make string from array
....
$wow = unserialize($_SESSION['wow']); // make array from string
echo $wow['color'];
iamler
Forum Newbie
Posts: 2 Joined: Wed Jun 25, 2003 5:57 am
Location: Thailand
Post
by iamler » Wed Jun 25, 2003 7:57 am
...