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

Posted by Jerry Stuckle on 07/16/06 14:01

Bent Stigsen wrote:
> 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.
>

True, I'm not using it in the C sense. But I'm not using "define" in
the Cobol sense, either :-). In PHP, assigning a value to a variable
defines it. And it can't be used anyplace other then the left side of
an assignment operator (rvalue in C terms) until it is defined.

However, most C programmers aren't aware of the terms lvalue and rvalue,
either, or if they are, have only a hazy idea of what they mean.

> 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.
>

That's true - I've gone through some awfully large files and databases
myself. But I've never had to create an array of 30K items in PHP, either.

Now in C/C++ I have done this. But these programs are typically much
more complex than PHP programs. For instance - I haven't seen too many
500K LOC PHP programs. But I have worked on several over the years in
C/C++.

My point being - PHP is a different language - and one should be
approaching PHP development differently than C/C++ development.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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