Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

want to loop foreach number in a list

Posted on 2010-09-02
4
Medium Priority
?
182 Views
Last Modified: 2012-05-10
i have a list of numbers 'numbers'
56
46
57
89
76

foreach (numbers as $n){

echo $n;
do something
}
0
Comment
Question by:rgb192
  • 2
4 Comments
 
LVL 44

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 33591955
Not really sure that's a question.

You use the foreach loop on an array, so as long as your numbers are in an array, then you can loop.

$numbers = array(56, 46, 57, 89, 76);

foreach ($numbers as $n)
{
echo "Your number is " . $n;
}

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 33592066
foreach() is a control structure, documented on the PHP web page here.  It operates on arrays and objects, not lists.  Please show us how your list of numbers is organized.
http://us2.php.net/manual/en/control-structures.foreach.php
0
 

Author Comment

by:rgb192
ID: 33612704
56
46
57
89
76

these are the numbers
I want to copy paste the numbers into the php code
0
 

Author Closing Comment

by:rgb192
ID: 33612715
yes,  this answered my question

thank you
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question