Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating an array as a property of an object

0 views
Skip to first unread message

Ken Kixmoeller -- reply to ken@kixmoeller.com

unread,
Jan 26, 2007, 4:09:30 PM1/26/07
to php-g...@lists.php.net
Hello, folks -- lurking for a while, first post --

I'm relatively new to PHP but doing database design work for nearly
20 years.

I've RTFM'ed (+ books + other resources) a bunch of times but I have
a mental block around doing this:

I want to have an multidimensional array as a property of an object.

Example:

MySQL Resource:
WHAM_ID NAME AMOUNT
5 Fred 99
9 Albert 345
23 Mary 5
(etc...)

Inside the function which builds the instance of the object, I have
language like:

while ($line = mysql_fetch_array($result_set,MYSQL_ASSOC))
{
$this->foom_array = array("MyKey".$line["wham_id"]=>array($line).",";
}
This isn't even close. <g>

Any examples, or a well-written resource to help me do this?

TIA

Ken

Robert Cummings

unread,
Jan 26, 2007, 4:08:27 PM1/26/07
to Ken Kixmoeller -- reply to ken@kixmoeller.com, php-g...@lists.php.net
On Fri, 2007-01-26 at 15:09 -0600, Ken Kixmoeller -- reply to

k...@kixmoeller.com wrote:
> Hello, folks -- lurking for a while, first post --
>
> I'm relatively new to PHP but doing database design work for nearly
> 20 years.
>
> I've RTFM'ed (+ books + other resources) a bunch of times but I have
> a mental block around doing this:
>
> I want to have an multidimensional array as a property of an object.
>
> Example:
>
> MySQL Resource:
> WHAM_ID NAME AMOUNT
> 5 Fred 99
> 9 Albert 345
> 23 Mary 5
> (etc...)
>
> Inside the function which builds the instance of the object, I have
> language like:
>
> while ($line = mysql_fetch_array($result_set,MYSQL_ASSOC))
> {
> $this->foom_array = array("MyKey".$line["wham_id"]=>array($line).",";

$this->foom_array[$line['WHAM_ID']] = $line;

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

Ken Kixmoeller -- reply to ken@kixmoeller.com

unread,
Jan 26, 2007, 4:21:21 PM1/26/07
to php-g...@lists.php.net

On Jan 26, 2007, at 3:08 PM, Robert Cummings wrote:

> $this->foom_array[$line['WHAM_ID']] = $line;
>
> Cheers,
> Rob.

Thank you so much, Rob. That did it. (Kickin' the cobwebs out of my
head...)

Richard Lynch

unread,
Jan 29, 2007, 7:58:23 PM1/29/07
to Ken Kixmoeller -- reply to ken@kixmoeller.com, php-g...@lists.php.net
On Fri, January 26, 2007 3:09 pm, Ken Kixmoeller -- reply to

k...@kixmoeller.com wrote:
> I want to have an multidimensional array as a property of an object.

While not relevant to your immediate question, you may want to be told
that PHP arrays are not truly multi-dimensional, but nested.

I.e., one cannot do:
$foo[0] = 'bar';
$foo[0][] = 'baz';

$foo[0] can hold a value, or another array, but not both.

This confuses some "converts" from other languages which store data
differently in a "true" multi-dimensional fashion.

YMMV
NAIAA

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

0 new messages