473,491 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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]." ";
}
}
}

?>
Jan 17 '07 #1
2 1630
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:
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]." ";
}
}
}

?>
Jan 17 '07 #2
Antoine Merieux wrote:
Hi,
I'm trying to use associative array in another associative array
<snip>
>
$_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.
Jan 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2519
by: Stefan Richter | last post by:
Hi, I want to create an associative Array with a PHP variable (article ID) as Key and another associative array as it's value. How do I instanciate it, how can I fill it? I want something...
27
11116
by: Abdullah Kauchali | last post by:
Hi folks, Can one rely on the order of keys inserted into an associative Javascript array? For example: var o = new Object(); o = "Adam"; o = "Eve";
6
1994
by: mark4asp | last post by:
Suppose I have the following code. It functions to randomly select a city based upon the probabilities given by the key differences in the associative array. . Eg. because the key difference...
4
2650
by: Robert | last post by:
I am curious why some people feel that Javascript doesn't have associative arrays. I got these definitions of associative arrays via goggle: Arrays in which the indices may be numbers or...
8
7673
by: Derek Basch | last post by:
Is there any way to associate name/value pairs during an array initialization? Like so: sType = "funFilter" filterTypeInfo = ; filterTypeInfo = new Array("type" : sType); I can do it using...
47
5023
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
5
37679
by: soup_or_power | last post by:
Hi I have an associative array like this: arr=30; arr=20;arr=40;arr=10; I want the sort function to sort keys in ascending order of the values on the right hand side with the following result:...
7
39827
by: Robert Mark Bram | last post by:
Hi All! How do you get the length of an associative array? var my_cars= new Array() my_cars="Mustang"; my_cars="Station Wagon"; my_cars="SUV"; alert(my_cars.length);
41
4873
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
11
2912
by: Bosconian | last post by:
I'm trying to output the contents of an array of associative arrays in JavaScript. I'm looking for an equivalent of foreach in PHP. Example: var games = new Array(); var teams = new...
0
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.