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

display the value error

karthickRAJKUMAR
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.      $counter= array();
  3.      for ($n=1;$n<=3;$n++)
  4.              {
  5.  
  6.             echo $counter[$n];
  7.         }
  8.  
  9.    ?>

it will not display 1,2,3 why?or i want display
Oct 4 '07 #1
3 1261
ak1dnar
1,584 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $counter= array(); // This is a Empty Array
  3. array_push($counter,"Some_value"); // You have to Assign values To Array LIke This
  4. array_push($counter,"Another_value");
  5. array_push($counter,"One_More_value");
  6. // Then You can Print "0"th,"1"st,"2" nd elements of the Array Like this
  7. for ($n=0;$n<=3;$n++)
  8. {
  9. echo $counter[$n];
  10. }
  11. echo "<br>";
  12. // if you want to just print 1,2,3 No need of array this is enough
  13.  
  14. for ($n=1;$n<=3;$n++)
  15. {
  16. echo $n.',';
  17. }
  18. ?>
  19.  
Please Use the CODE tags in future.Thanks.
[code=php]
..your codes goes here
[ /code]
Oct 4 '07 #2
Atli
5,058 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $counter= array(); // This is a Empty Array
  3. array_push($counter,"Some_value"); // You have to Assign values To Array LIke This
  4. array_push($counter,"Another_value");
  5. array_push($counter,"One_More_value");
  6. ?>
  7.  
Hi.

That can also be accomplished like this: (my personal preference)
Expand|Select|Wrap|Line Numbers
  1. $counter = array();
  2. $counter[] = "First";
  3. $counter[] = "Second";
  4. $counter[] = "Third";
  5.  
And even like this:
Expand|Select|Wrap|Line Numbers
  1. $counter = array(
  2.   0 => "First",
  3.   1 => "Second",
  4.   2 => "Third"
  5. );
  6.  
These three methods all do the same thing, just a matter of preference which one you use.

The original problem, as I am sure you have gathered after ajaxrand's post, is that the array, $counter, has no elements. Thus, calling elements, no matter at what index, will not yield any results and should print a "Notice: Undefined index...".
Oct 4 '07 #3
pbmods
5,821 Expert 4TB
Hi.

That can also be accomplished like this: (my personal preference)
Expand|Select|Wrap|Line Numbers
  1. $counter = array();
  2. $counter[] = "First";
  3. $counter[] = "Second";
  4. $counter[] = "Third";
  5.  
And even like this:
Expand|Select|Wrap|Line Numbers
  1. $counter = array(
  2.   0 => "First",
  3.   1 => "Second",
  4.   2 => "Third"
  5. );
  6.  
These three methods all do the same thing, just a matter of preference which one you use.
Note that the last method is actually the fastest because you are only executing a single statement.

And for maximum efficiency:
Expand|Select|Wrap|Line Numbers
  1. $counter =
  2.     array
  3.     (
  4.         'First',
  5.         'Second',
  6.         'Third'
  7.     );
  8.  
Oct 4 '07 #4

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

Similar topics

10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
7
by: Stefan Finzel | last post by:
Hi, is there a way to change the display property on Windows Mobile 2003 SE Mobile/Pocket Internet Explorer? See following example. Please note: visibilty property has the same problem. Is...
13
by: Benjamin Smith | last post by:
I am controlling the display status of a table row using the following code. <TR id="CCRow" style="DISPLAY:none"> Instead of hard coding "none" above, I would like to change that value using a...
1
by: rbinington | last post by:
Hi, I am trying to write a DNN module that has the ability to insert articles into an article repository. I want the users to be able to move pages around and enter text into the FCKEditor. I...
3
by: getintanked | last post by:
<script language="javascript" type="text/javascript"> function budgetview() { if (document.form1.txtSubject.value == "Weddings") { document.getElementById(BudgetDiv).style.display='block'; } }...
1
by: Bob | last post by:
Hi, Hope you can help me with this one. I'm at my wits end. I'm trying to create an intelligent edit-box like the excellent "Customer" one at the URL: ...
36
by: beebelbrox | last post by:
Hi, I am new VB programming in Access and I am requesting help with the following code. WIndows OS MSaccess 2003 This code is attached to an unbound form that will display a specific recordset...
3
by: koutoo | last post by:
Is it possible to display messages in the python shell? I want to display error messages based on parameters in my scripts to the users. Is there another way to display messages other than log...
9
by: tshad | last post by:
I have a Windows App that is doing some work and then writing a "Now Processing..." line to the status line of the window as well as the Textbox on the form. But the problem is that the work is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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,...
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
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...

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.