473,320 Members | 1,829 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,320 software developers and data experts.

.. count shortcut

I need to make an array of 1 to X items

in perl , this would be: 1..X .

Is there such a thing in php, or do I need to make a loop?

Jeff
Sep 9 '08 #1
4 1522
..oO(Jeff)
I need to make an array of 1 to X items

in perl , this would be: 1..X .

Is there such a thing in php, or do I need to make a loop?
range() maybe?

Micha
Sep 9 '08 #2
Michael Fesser wrote:
.oO(Jeff)
> I need to make an array of 1 to X items

in perl , this would be: 1..X .

Is there such a thing in php, or do I need to make a loop?

range() maybe?
perfect!

Even more useful than the perl construct.

Jeff
>
Micha
Sep 9 '08 #3
Jeff wrote:
>> I need to make an array of 1 to X items

in perl , this would be: 1..X .

Is there such a thing in php, or do I need to make a loop?

range() maybe?

perfect!

Even more useful than the perl construct.
Just be aware that

$arr = array();
foreach (range(0,count($arr)-1) as $i) print "$i\n";

and

my @arr = ();
for my $i (0 .. $#arr) { print "$i\n"; }
behaves differently.
Sep 9 '08 #4
Matija Papec wrote:
Jeff wrote:
>>> I need to make an array of 1 to X items

in perl , this would be: 1..X .

Is there such a thing in php, or do I need to make a loop?

range() maybe?

perfect!

Even more useful than the perl construct.

Just be aware that

$arr = array();
foreach (range(0,count($arr)-1) as $i) print "$i\n";

and

my @arr = ();
for my $i (0 .. $#arr) { print "$i\n"; }
behaves differently.
They do behave the same (ran each at the command line to be sure).
Maybe you didn't mean to subtract 1 from count($arr), in the PHP example.

These two are the same:

PHP
$indexes = range(0, count($arr)-1);

Perl
my @indexes = (0..$#arr);

So are these:

PHP
$elements = range(0, count($arr));

Perl
my @elements = (0 .. scalar @arr);

--
Curtis
Sep 10 '08 #5

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

Similar topics

27
by: aa | last post by:
Thought this question might be out of this NG's scope, there are always knowledgable people who might hava an answer. A hyperlink to a shortcut to a file returnes an empty screen, and the source...
4
by: Salad | last post by:
A97. If you set a forms properties to ShortcutMenu = No, the entire form is disabled from displaying a shortcut menu. If you set the property to Yes, all controls have a shortcut menu. I have...
1
by: James | last post by:
Access 2003, trying to count the number of records that meet a criteria. According to Help: "In the Database window, click Queries under Objects, and then click New on the database window...
0
by: cefrancke | last post by:
I recently discovered, that if you set the startup options for "security", you will have alot of work do to get Access back to "normal". If you disable the built-in menus/toolbars you'll have to...
4
by: I_AM_DON_AND_YOU? | last post by:
There is one more problem I am facing but didn't get the solution. In my Setup Program I am not been able to create 2 things (when the program is intalled on the client machine ) : (1) create...
3
by: TC | last post by:
I've written an application using VB.NET 2003 and packaged it with a deployment project. When I use the setup program to install the application, however, it doesn't work. More specifically, the...
7
by: GrandpaB | last post by:
I would appreciate assistance learning how to create a Desktop shortcut in my setup project. In the left pane of the Setup/File System window I right-clicked User's Desktop. From the contex...
1
by: Derek Hart | last post by:
I wish to get a count of nodes in an xml file in vb.net, so I am using the following, as a simple example: MyCount = xmlNodePart.Current.Select.//MyNode/Record).Count I saw in some xml...
5
by: remya1000 | last post by:
i'm using VB.NET 2003 application program. by using OpenFileDialog, we can select the file name or file path. OpenFileDialog1.ShowDialog() pgmPath.Text =...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.