Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old January 17th, 2007, 10:05 PM
Antoine Merieux
Guest
 
Posts: n/a
Default associative array in associative array

Hi,
I'm trying to use associative array in another associative array

to feed it's ok
to retrieve, something's wrong
can you help me
thank you

<?php
session_start();
$tabItems = array(49, 59, 69, 79);
$tabExercice = array(
'1' =$tabItems,
'45' =$tabItems);

$tab = array(
'487' =$tabExercice,
'45' =$tabExercice,
'23' =$tabExercice);

$_SESSION['caddy'] = $tab;

//print_r($tab);

// Let see what is it
foreach ($tab as $k =$v) {
// the key is id_focus
echo "Liste des exercices pour le focus".$k;
foreach ($k as $k2 =$v2) {
// the key is id_exo
echo "<br>id_exo =".$k2;
echo "<br>liste des items";
for ($i=0; $i < count($v2); $i++)
{
echo $v2[$i]." ";
}
}
}

?>
  #2  
Old January 17th, 2007, 10:35 PM
Michael Cooney
Guest
 
Posts: n/a
Default Re: associative array in associative array

In your nested foreach, you're trying to loop over the key as opposed
to the nested array.

Change:
foreach ($k as $k2 =$v2) {
to:
foreach ($v as $k2 =$v2) {

Antoine Merieux wrote:
Quote:
Hi,
I'm trying to use associative array in another associative array
>
to feed it's ok
to retrieve, something's wrong
can you help me
thank you
>
<?php
session_start();
$tabItems = array(49, 59, 69, 79);
$tabExercice = array(
'1' =$tabItems,
'45' =$tabItems);
>
$tab = array(
'487' =$tabExercice,
'45' =$tabExercice,
'23' =$tabExercice);
>
$_SESSION['caddy'] = $tab;
>
//print_r($tab);
>
// Let see what is it
foreach ($tab as $k =$v) {
// the key is id_focus
echo "Liste des exercices pour le focus".$k;
foreach ($k as $k2 =$v2) {
// the key is id_exo
echo "<br>id_exo =".$k2;
echo "<br>liste des items";
for ($i=0; $i < count($v2); $i++)
{
echo $v2[$i]." ";
}
}
}
>
?>
  #3  
Old January 18th, 2007, 09:15 PM
Colin McKinnon
Guest
 
Posts: n/a
Default Re: associative array in associative array

Antoine Merieux wrote:
Quote:
Hi,
I'm trying to use associative array in another associative array
>
<snip>
Quote:
>
$_SESSION['caddy'] = $tab;
In PHP4, arrays behave as if they only hold scalars in some regards (similar
to Perl) possibly in PHP5 too.

Try serializing the data before putting it in a session variable.

HTH

C.
 

Bookmarks

Thread Tools

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles