473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to print elemnets of N-dimensional array?

Hello,

What is a common way to print elements of a multidimensional array? I
treid to do it in the straightforward way:
$input_list[0][0] = "Something";
print "$input_list[0][0]";
And it does not work.

The solution that I found is to use intermediate variable:
$array = $input_list[0];
print "$array[0]";
printArray( $output_list[0] );

Are there any more elegant (or just common) ways to do it?

Jul 17 '05 #1
3 1704
op*********@yahoo.com wrote:
What is a common way to print elements of a multidimensional array? I
treid to do it in the straightforward way:
$input_list[0][0] = "Something";
print "$input_list[0][0]";
And it does not work.


Either one of the following should work:

print $input_list[0][0];
print "{$input_list[0][0]}";

Notice the braces used in the second example.
JW

Jul 17 '05 #2
op*********@yahoo.com wrote in news:1109517346.824559.113520
@f14g2000cwb.googlegroups.com:
Hello,

What is a common way to print elements of a multidimensional array? I
treid to do it in the straightforward way:
$input_list[0][0] = "Something";
print "$input_list[0][0]";
And it does not work.


You're close. PHP automatically expands variables inside of quotation
marks. Thus, when you write

print "$input_list[0][0]";

PHP sees this as a string because it's in quotation marks, and attempts
to replace the text "$input_list" with the value of the $input_list
variable. In this case, $input_list is an array, and trying to print or
echo an array by name results in the string "Array."

To solve this problem, just remove the quotation marks:

print $input_list[0][0];

hth
--
Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.arg');
--------------------------|---------------------------------
<http://www.phplabs.com/> | PHP scripts, webmaster resources
Jul 17 '05 #3
Senator Jay Billington Bulworth wrote:
op*********@yahoo.com wrote in news:1109517346.824559.113520
@f14g2000cwb.googlegroups.com:

Hello,

What is a common way to print elements of a multidimensional array? I
treid to do it in the straightforward way:
$input_list[0][0] = "Something";
print "$input_list[0][0]";
And it does not work.

You're close. PHP automatically expands variables inside of quotation
marks. Thus, when you write

print "$input_list[0][0]";

PHP sees this as a string because it's in quotation marks, and attempts
to replace the text "$input_list" with the value of the $input_list
variable. In this case, $input_list is an array, and trying to print or
echo an array by name results in the string "Array."

To solve this problem, just remove the quotation marks:

print $input_list[0][0];

Or, if you need to print the value embedded in a string, do this:

print "{$input_list[0][0]}";

HTH,
JP

--
Sorry, <de*****@cauce.org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
Jul 17 '05 #4

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

Similar topics

12
by: Michael Foord | last post by:
Here's a little oddity with 'print' being a reserved word... >>> class thing: pass >>> something = thing() >>> something.print = 3 SyntaxError: invalid syntax >>> print something.__dict__...
14
by: Marcin Ciura | last post by:
Here is a pre-PEP about print that I wrote recently. Please let me know what is the community's opinion on it. Cheers, Marcin PEP: XXX Title: Print Without Intervening Space Version:...
0
by: bearophileHUGS | last post by:
There is/was a long discussion about the replacement for print in Python 3.0 (I don't know if this discussion is finished): http://mail.python.org/pipermail/python-dev/2005-September/055968.html ...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
3
by: James J. Besemer | last post by:
I would like to champion a proposed enhancement to Python. I describe the basic idea below, in order to gage community interest. Right now, it's only an idea, and I'm sure there's room for...
69
by: Edward K Ream | last post by:
The pros and cons of making 'print' a function in Python 3.x are well discussed at: http://mail.python.org/pipermail/python-dev/2005-September/056154.html Alas, it appears that the effect of...
2
by: Brad Pears | last post by:
I have some sample code that uses the print dialog, print preview and a print direct options. If I select print preview and then click the printer icon from that, the document prints. If I...
7
by: samslists | last post by:
Am I the only one that thinks this would be useful? :) I'd really like to be able to use python 3.0's print statement in 2.x. Is this at least being considered as an option for 2.6? It seems...
12
by: Studiotyphoon | last post by:
Hi, I have report which I need to print 3 times, but would like to have the following headings Customer Copy - Print 1 Accounts Copy - Print 2 File Copy -Print 3 I created a macro to...
2
by: ravir81 | last post by:
Hi, I am working on excel reporting using Perl. I am facing problem with writing the header part only once for all the excels created using Perl. Here is the code : ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...

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.