473,800 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multidimensiona l associated array

Hi,

I try to construct an array such that each element of it is another
array returned by the fetch_array_fun ction:

for ( $i = 1; $i<=$n; $i++ )
{
$ar[$i] = mysql_fetch_arr ay( $result );
print "$ar[$i][fieldname]\n";
}

It prints "Array[fieldname]".

If I replace $ar[$i] by $ar everything works fine! Could you pleas
help me with that?
Jan 12 '08 #1
9 2152
Kurda Yon wrote:
Hi,

I try to construct an array such that each element of it is another
array returned by the fetch_array_fun ction:

for ( $i = 1; $i<=$n; $i++ )
{
$ar[$i] = mysql_fetch_arr ay( $result );
print "$ar[$i][fieldname]\n";
}

It prints "Array[fieldname]".

If I replace $ar[$i] by $ar everything works fine! Could you pleas
help me with that?
print $ar[$i]['fieldname'] . "\n";
or
print "{$ar[$i]['fieldname']\n";

[fieldname] will give you an E_NOTICE if enabled (and it should be on
your development system).

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Jan 12 '08 #2
Jerry Stuckle wrote:
Kurda Yon wrote:
>Hi,

I try to construct an array such that each element of it is another
array returned by the fetch_array_fun ction:

for ( $i = 1; $i<=$n; $i++ )
{
$ar[$i] = mysql_fetch_arr ay( $result );
print "$ar[$i][fieldname]\n";
}

It prints "Array[fieldname]".

If I replace $ar[$i] by $ar everything works fine! Could you pleas
help me with that?

print $ar[$i]['fieldname'] . "\n";
or
print "{$ar[$i]['fieldname']}\n";

[fieldname] will give you an E_NOTICE if enabled (and it should be on
your development system).
A notice is not thrown in this case because the key is already within
double quotes. The problem is fixed by the necessity to use { }'s when
using multi-dimensional arrays within double quotes. I normally use this
method. To get PHP to throw a NOTICE, remove the single quotes from your
second example.

--
Norman
Registered Linux user #461062
Jan 12 '08 #3
print_r will show you the internals
Jan 13 '08 #4
no point for you to control the index yourself
<?php
$a[] = 2;
$a[] = 3;
$a[] = 5;
print $a;
print_r($a);
?>
Jan 13 '08 #5
<?php
$a = array(array("a" =>1, "b"=>2));
print "{$a[0]['b']}";
?>
Jan 13 '08 #6
you obviously forgot to close your }
Jan 13 '08 #7
<?php
$a = array(array("a" =>1, "b"=>2));
print "{$a[0][b]}";
?>
this gives you notice,
Jan 13 '08 #8
php ends the variable name at the most convenience spot
Jan 13 '08 #9
Peter Pei wrote:
<?php
$a = array(array("a" =>1, "b"=>2));
print "{$a[0][b]}";
?>
this gives you notice,
Yes, that's what I said. When using multi-dimensional arrays within
double-quoted strings you must use the { }'s... and when you use the {
}'s you must use single quotes around the key names. PHP does not search
for CONSTANTS within double-quoted strings, there is a very specific
reason for it.
--
Norman
Registered Linux user #461062
Jan 14 '08 #10

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

Similar topics

9
6675
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the function (which was translated from Fortran code), among other heinous and numerous declarations, is this bit: static float bbuff; static int bkey; static int buse;
7
7024
by: bijax | last post by:
hi, i am new to multidimensional array of c programming .pls help me to solve out this how to allocate memory for mutidimensional array? i.e a ;
1
8288
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a RankException. But the MSDN documentation says: When copying between multidimensional arrays, the array
2
12837
by: chris | last post by:
Hi there, I created a Multidimensional array of labels Label lblMultiArray = new Label { {Label3, LblThuTotal}, {Label4,LblFriTotal} }; Now I would like to compare the values in the array, comparing the text in Label3 and LblThuTotal and the text in Label4 and LblFriTotal.
21
4205
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if possible. The thing I am trying to do is to convert a double value to a string with 8 elements. 8 is fixed because of the files I work with. I will change this 8 character string with the one(8 character string) already in the file and so on. But I...
10
12215
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to help do the most basic things. One of the "basic" things I haven't been able to find out how to do is how to delete an item from a multidimensional array object and resize it afterwards. It seems so easy to conceive of the code to delete...
1
9795
by: Chuy08 | last post by:
If I have a multidimensional array like the following: Array $records =Array 0 = 30 year, 6.0; 1 = 30 year, 6.0; 2 = Pay Option, 1.0; 3 = Pay Option, 1.0; How could I flatten this to achieve an array that only has unique Product
5
2321
by: LittleCake | last post by:
Hi All, I have a multidimensional array where each sub-array contains just two entries, which indicates a relationship between those two entries. for example the first sub-array: =Array ( =30 =31 )
4
2514
Jezternz
by: Jezternz | last post by:
First of all I am open to any suggestions and advice. If a javscript multidimensional array is a bad way to do this please say so. I considered XML but I wondered if this would be a bad idea as it would be slower for jsp to handel. Okay here is an example of my multidimensional array (only part of it)(bottom of the post). It works fine I can call any of the 3rd dimension without trouble. Now How would I go about printing something like...
9
4503
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize function: x = new int;
0
9694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10256
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10039
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9095
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7584
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5477
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4152
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.