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

Is it a bad idea to declare an array as array(-1) ?

I got the question from someone at the office. He was converting some code to php code.

He saw "$var = array(-1);" somewhere.
On the internets people say it's better to use (0) then (-1), but no-one says why exactly.

Can harm come from the array(-1) ?
Jul 8 '10 #1
4 1288
zorgi
431 Expert 256MB
$var = array(-1); is not the same as $var = array(0);. They are both arrays but they are arrays with different elements.

I do not understand your question.
Jul 8 '10 #2
Markus
6,050 Expert 4TB
I don't understand why initializing an array with a single element that has the value -1 could be harmful? You're creating an issue where there isn't one.
Jul 8 '10 #3
ok, thanks. just wanted to be sure
Jul 9 '10 #4
Dormilich
8,658 Expert Mod 8TB
it might be different, if you consider languages like JavaScript, where passing a single value to the array constructor will set the array length (or any other object specific setting).

but that’s not the case for PHP.
Jul 10 '10 #5

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

Similar topics

3
by: Nicolas Fleury | last post by:
Hi, Does anyone know if arrays would be picklable in python 2.4? Until then, I tried to derive from array.array and add __setstate__ and __getstate__ with the following code, but it seems I'm not...
2
by: Gus Tabares | last post by:
Hello all, I'm trying to subclass array.array but having problems with a default parameter in the init constructor. Example: import array class TestClass(array.array): def __init__(self,...
4
by: Majid Mohammadian | last post by:
Hi All, I want declare an array of int in SQL Server please help me to convert the following code from VB to TSQL ------------ Dim md_mon(12) As Integer md_mon(1) = 31 ------------- Thanks
6
by: Dylan Nicholson | last post by:
Is there any way of declaring the parameter "array" below to be const, so that the function as written will not compile: void foo(int array /*const*/) { array = array; // should not be allowed...
5
by: Ingo Brueckl | last post by:
I need to declare a fixed array of (already defined and working) sort functions (sortfunc1, sortfunc2, sortfunc3) to pass one element of the array to qsort itself: int index; ??? func =...
3
by: Himmat Solanki via .NET 247 | last post by:
How can we declare an array that have not afix length? and can it possible to inserts new itmes to it? as much as we want to enter. -------------------------------- From: Himmat Solanki ...
8
by: redefined.horizons | last post by:
I would like to have an array declaration where the size of the array is dependent on a variable. Something like this: /* Store the desired size of the array in a variable named "array_size". */...
6
by: pallavi27 | last post by:
HI, i want to declare an array that should accept any size given by the user.how to declare such array?please explain me with the help of a code..it should display on the screen "enter the no of...
8
by: Gary | last post by:
When you declare an array of chars and store a string in it, where is the position of the null character \0? And what happens to the unused memory locations? #include <stdio.h> int main(void)...
1
by: Fabio | last post by:
Hi All, I have a question concerning the use of array.array inside of C++ code I wrote. I am working with _big_ data files but some entries in these files are usually bounded say between -5 to...
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: 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,...
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...

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.