You are here: Re: multidimensional array declaration in php « PHP Programming Language « IT news, forums, messages
Re: multidimensional array declaration in php

Posted by Bent Stigsen on 07/16/06 12:01

Jerry Stuckle wrote:
> vito wrote:
[snip]
>> Indeed, i just hope to make an array of a[10000][3] and then can be used
>> later. i'd be glad if you could tell me how to initialize such an array.
>> Thanks.

vito,
Your code should do the trick, that is making an array of 10000 elements,
each containing an array of 3 elements, each set to integer value zero, if
that is the intention. Can't say why you get the notice. 2700 shouldn't be
an undefined offset.

Notice that Jerry keep using the word *define*. Should probably be
emphasized since you're a C-programmer. There is no explicit declaration of
a variable like you would do in C, as it is just a generic storage-place
for a value, which content can be defined or not.
Even if not defined, a legal expression of an lvalue can be assigned a
value. PHP will happily create/extend arrays or objects if needed. Used as
a rvalue (like in your case) you will get a notice of this, but it can
safely be ignored (or suppressed with @) if the use is intended.

PHP will also quite happily coerce pretty much anything into something else.
E.g. you give all $array[$j][$k] the integer value 0, but later concatenate
$array[$i][1] with something else as if a string. Sometimes such automatic
typecasting makes sense, sometimes not.
The really good thing about it, is that it lets you write rather silly
things that actually works. Really takes the r out of boring.
Just for the point:
$array= array('is what we need').'_';
$indeed=$array.= @${', Hong Kong, we got an array to'}.'fill';
$array= $indeed("of","10000 rows. Each an",$array('with',3,@${'cats'}));

....which really just is:

$array = array_fill(0, 10000, array_fill(0, 3, null));

> OK, here's a good place to start with arrays:
>
> http://us3.php.net/manual/en/language.types.array.php
>
> However, I still fail to see why you need to define 30K elements.
> That's an awful lot for a PHP routine. But you know more about what
> you're doing.

Well, yeah, sometimes one just find the urge to try something and see how it
goes. Perhaps that is vito's deal.
I once tried using php to traverse 3 Mill. records from a db. Nothing fancy
I thought, just one at the time, do a "little" fiddling and occasionally
throw a chunk someplace else. Needless to say perhaps, I ended up doing it
in C instead.

--
/Bent

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация