473,396 Members | 2,020 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,396 software developers and data experts.

Command to Print or Echo all Elements of an Array?

tharden3
916 512MB
Is there a quick way to ask to 'echo' or 'print' all elements of a numeric array? Can I specify to print "all of the keys" or "all of the values"? I wrote up 5 quick lines of code to print all of my values, but there has to be a built_in function I can call to do that for me right? Like function($months) or something?
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $months=array('January','February','March','April');
  3. $key=0;
  4. $calendar=count($months);
  5. while($key<=$calendar){
  6. echo "$months[$key]<br/>";
  7. $key++;}
  8. ?>
  9.  
Do I use var_dump()? This would allow me to see the entire thing, but what if I only want to specify 'just keys' or 'just values'?
Jan 3 '09 #1
3 9426
Dormilich
8,658 Expert Mod 8TB
@tharden3
does it really matter if you see both values? I'm glad for any information I get...

regards
Jan 3 '09 #2
Atli
5,058 Expert 4TB
Hi.

You can use print_r to see your array in a formatted way.
I usually just do:
Expand|Select|Wrap|Line Numbers
  1. echo "<pre>", print_r($array, true), "</pre>";
when I need to debug an array in my web pages in a hurry.

If you need to filter or change the array before you show it, one of the Array Functions can most likely do that for you before you print it.

P.S.
Check out the foreach loop
Expand|Select|Wrap|Line Numbers
  1. foreach($months as $month) {
  2.   echo "$month<br />";
  3. }
Jan 3 '09 #3
tharden3
916 512MB
Oh, ok. That's like saying, "for x in this, do this". Thanks for the help.
Jan 3 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: opt_inf_env | last post by:
Hello, What is a common way to print elements of a multidimensional array? I treid to do it in the straightforward way: $input_list = "Something"; print "$input_list"; And it does not work. ...
4
by: Shailesh | last post by:
Hi! I want to overload << operator so that it can print an arry defined in MyClass.My problem is that I want to print only a no of elements NOT all the elements in the array and this no of...
2
by: Dave Thomas | last post by:
I have an array, say something like this (to build a form): $commands = array( "Start Date" => "build_date('startdate')", "End Date" => "build_date('enddate')" ); Only it will have many more...
3
by: Eli Criffield | last post by:
I'm try run an ssh command in pexpect and I'm having trouble getting everything escaped to do what i want. Here's a striped down script showing what i want to do. -- #!/usr/bin/env python...
2
by: mordac | last post by:
Hello, I was wondering if I could get some opinions on how best to handle printing in a max heap data structure. Right now my heap struct looks as thus: typedef struct heapStruct { int*...
1
by: Steff | last post by:
I am wandering if my code is making sense... I use a lot the print function. Is it weird in this case where I have to display an array ? I thought it would be better to have the entire array in php...
1
by: Manish | last post by:
I have the following code in a script -------------------------------------------------------------------------------------------------------------------------------- foreach($serverlist as...
4
by: j_depp_99 | last post by:
Thanks to those guys who helped me out yesterday. I have one more problem; my print function for the queue program doesnt work and goes into an endless loop. Also I am unable to calculate the...
1
by: sheel331 | last post by:
Hello, I am new to coding in PHP, and had a question about a simple thing: I am trying to echo out the elements of an array for a sidenav in one of my HTML pages, and I can't seem to figure out...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
0
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
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,...

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.