Multi Array?

This is a discussion on Multi Array? within the PHP Language forums, part of the PHP Programming Forums category; Hi, I'm not sure how to do this. Let's say I have an array that looks like this: $...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-26-2008
Mtek
 
Posts: n/a
Default Multi Array?


Hi,

I'm not sure how to do this. Let's say I have an array that looks
like this:

$timing[$x] = array('Count' => 0);

So, basically I've initialized that element of the array with another
array item, that being 'Count'. Later, I want to add another item to
the array, like this:

$timing[$x] = array('Start' => date ("g:i:s"));

How would I do that? I'm sure I cannot use the 'array' function more
than once........do I need to define it and initialize it with nulls?

Along those same lines, can I do something like this: $timing[$x]
['Count']++;

I'm looking for examples, but not finding any on the web. If someone
can help, I'd really appreciate it.

Thank you,

John
Reply With Quote
  #2 (permalink)  
Old 05-26-2008
Norman Peelman
 
Posts: n/a
Default Re: Multi Array?

Mtek wrote:
> Hi,
>
> I'm not sure how to do this. Let's say I have an array that looks
> like this:
>
> $timing[$x] = array('Count' => 0);
>
> So, basically I've initialized that element of the array with another
> array item, that being 'Count'. Later, I want to add another item to
> the array, like this:
>
> $timing[$x] = array('Start' => date ("g:i:s"));
>
> How would I do that? I'm sure I cannot use the 'array' function more
> than once........do I need to define it and initialize it with nulls?
>
> Along those same lines, can I do something like this: $timing[$x]
> ['Count']++;
>
> I'm looking for examples, but not finding any on the web. If someone
> can help, I'd really appreciate it.
>
> Thank you,
>
> John



This works:

$timing[$x]['Count'] = 0;
$timing[$x]['Start'] = date("g:i:s");

$timing[$x]['Count']++;

echo var_dump($timing);


--
Norman
Registered Linux user #461062
Reply With Quote
  #3 (permalink)  
Old 05-27-2008
Mtek
 
Posts: n/a
Default Re: Multi Array?

On May 26, 4:22*pm, Norman Peelman <npeel...@cfl.rr.com> wrote:
> Mtek wrote:
> > Hi,

>
> > I'm not sure how to do this. *Let's say I have an array that looks
> > like this:

>
> > $timing[$x] = array('Count' *=> 0);

>
> > So, basically I've initialized that element of the array with another
> > array item, that being 'Count'. *Later, I want to add another item to
> > the array, like this:

>
> > $timing[$x] = array('Start' *=> date ("g:i:s"));

>
> > How would I do that? *I'm sure I cannot use the 'array' function more
> > than once........do I need to define it and initialize it with nulls?

>
> > Along those same lines, can I do something like this: *$timing[$x]
> > ['Count']++;

>
> > I'm looking for examples, but not finding any on the web. *If someone
> > can help, I'd really appreciate it.

>
> > Thank you,

>
> > John

>
> This works:
>
> $timing[$x]['Count'] = 0;
> $timing[$x]['Start'] = date("g:i:s");
>
> $timing[$x]['Count']++;
>
> echo var_dump($timing);
>
> --
> Norman
> Registered Linux user #461062- Hide quoted text -
>
> - Show quoted text -



What is the difference between that and something like this:

$tables[$x] = array('Acronym' => $table_data[0],
'List' => $table_data[1],
'Name' => $table_data[2]);


I'm really looking for a sturcture like this.......is there any
difference at all???
Reply With Quote
  #4 (permalink)  
Old 05-27-2008
Mtek
 
Posts: n/a
Default Re: Multi Array?

On May 26, 4:22*pm, Norman Peelman <npeel...@cfl.rr.com> wrote:
> Mtek wrote:
> > Hi,

>
> > I'm not sure how to do this. *Let's say I have an array that looks
> > like this:

>
> > $timing[$x] = array('Count' *=> 0);

>
> > So, basically I've initialized that element of the array with another
> > array item, that being 'Count'. *Later, I want to add another item to
> > the array, like this:

>
> > $timing[$x] = array('Start' *=> date ("g:i:s"));

>
> > How would I do that? *I'm sure I cannot use the 'array' function more
> > than once........do I need to define it and initialize it with nulls?

>
> > Along those same lines, can I do something like this: *$timing[$x]
> > ['Count']++;

>
> > I'm looking for examples, but not finding any on the web. *If someone
> > can help, I'd really appreciate it.

>
> > Thank you,

>
> > John

>
> This works:
>
> $timing[$x]['Count'] = 0;
> $timing[$x]['Start'] = date("g:i:s");
>
> $timing[$x]['Count']++;
>
> echo var_dump($timing);
>
> --
> Norman
> Registered Linux user #461062- Hide quoted text -
>
> - Show quoted text -



What is the difference between that and something like this:


$tables[$x] = array('Acronym' => $table_data[0],
'List' => $table_data[1],
'Name' => $table_data[2]);


I'm really looking for a sturcture like this.......is there any
difference at all???

What about this?

$summary[$x]['seating'] = array('Seating' => $row[0],
'Count' => $row[1]);

Is the word 'seating' like a section title or something?

John
Reply With Quote
  #5 (permalink)  
Old 05-27-2008
Jerry Stuckle
 
Posts: n/a
Default Re: Multi Array?

Mtek wrote:
> On May 26, 4:22 pm, Norman Peelman <npeel...@cfl.rr.com> wrote:
>> Mtek wrote:
>>> Hi,
>>> I'm not sure how to do this. Let's say I have an array that looks
>>> like this:
>>> $timing[$x] = array('Count' => 0);
>>> So, basically I've initialized that element of the array with another
>>> array item, that being 'Count'. Later, I want to add another item to
>>> the array, like this:
>>> $timing[$x] = array('Start' => date ("g:i:s"));
>>> How would I do that? I'm sure I cannot use the 'array' function more
>>> than once........do I need to define it and initialize it with nulls?
>>> Along those same lines, can I do something like this: $timing[$x]
>>> ['Count']++;
>>> I'm looking for examples, but not finding any on the web. If someone
>>> can help, I'd really appreciate it.
>>> Thank you,
>>> John

>> This works:
>>
>> $timing[$x]['Count'] = 0;
>> $timing[$x]['Start'] = date("g:i:s");
>>
>> $timing[$x]['Count']++;
>>
>> echo var_dump($timing);
>>
>> --
>> Norman
>> Registered Linux user #461062- Hide quoted text -
>>
>> - Show quoted text -

>
>
> What is the difference between that and something like this:
>
>
> $tables[$x] = array('Acronym' => $table_data[0],
> 'List' => $table_data[1],
> 'Name' => $table_data[2]);
>
>
> I'm really looking for a sturcture like this.......is there any
> difference at all???
>
> What about this?
>
> $summary[$x]['seating'] = array('Seating' => $row[0],
> 'Count' => $row[1]);
>
> Is the word 'seating' like a section title or something?
>
> John



$tables[$x] = array();

indicates $tables[$x] is an array itself.

$tables[$x] = array('Acronym' => $table_data[0],
'List' => $table_data[1],
'Name' => $table_data[2]);

Is just a shortcut method of initializing the array. The result is
exactly the same as:

$tables[$x] = array();
$tables[$x]['Acronym'] = $table_data[0];
$tables[$x]['List'] = $table_data[1];
$tables[$x]['Name'] = $table_data[2];

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #6 (permalink)  
Old 05-27-2008
Norman Peelman
 
Posts: n/a
Default Re: Multi Array?

Mtek wrote:
> On May 26, 4:22 pm, Norman Peelman <npeel...@cfl.rr.com> wrote:
>> Mtek wrote:
>>> Hi,
>>> I'm not sure how to do this. Let's say I have an array that looks
>>> like this:
>>> $timing[$x] = array('Count' => 0);
>>> So, basically I've initialized that element of the array with another
>>> array item, that being 'Count'. Later, I want to add another item to
>>> the array, like this:
>>> $timing[$x] = array('Start' => date ("g:i:s"));
>>> How would I do that? I'm sure I cannot use the 'array' function more
>>> than once........do I need to define it and initialize it with nulls?
>>> Along those same lines, can I do something like this: $timing[$x]
>>> ['Count']++;
>>> I'm looking for examples, but not finding any on the web. If someone
>>> can help, I'd really appreciate it.
>>> Thank you,
>>> John

>> This works:
>>
>> $timing[$x]['Count'] = 0;
>> $timing[$x]['Start'] = date("g:i:s");
>>
>> $timing[$x]['Count']++;
>>
>> echo var_dump($timing);
>>
>> --
>> Norman
>> Registered Linux user #461062- Hide quoted text -
>>
>> - Show quoted text -

>
>
> What is the difference between that and something like this:
>
>
> $tables[$x] = array('Acronym' => $table_data[0],
> 'List' => $table_data[1],
> 'Name' => $table_data[2]);
>
>
> I'm really looking for a sturcture like this.......is there any
> difference at all???
>


Same thing, I just didn't use the 'array' object to create them.

> What about this?
>
> $summary[$x]['seating'] = array('Seating' => $row[0],
> 'Count' => $row[1]);
>
> Is the word 'seating' like a section title or something?
>
> John



--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
Reply With Quote
  #7 (permalink)  
Old 05-27-2008
Mtek
 
Posts: n/a
Default Re: Multi Array?

On May 26, 7:01*pm, Norman Peelman <npeel...@cfl.rr.com> wrote:
> Mtek wrote:
> > On May 26, 4:22 pm, Norman Peelman <npeel...@cfl.rr.com> wrote:
> >> Mtek wrote:
> >>> Hi,
> >>> I'm not sure how to do this. *Let's say I have an array that looks
> >>> like this:
> >>> $timing[$x] = array('Count' *=> 0);
> >>> So, basically I've initialized that element of the array with another
> >>> array item, that being 'Count'. *Later, I want to add another item to
> >>> the array, like this:
> >>> $timing[$x] = array('Start' *=> date ("g:i:s"));
> >>> How would I do that? *I'm sure I cannot use the 'array' function more
> >>> than once........do I need to define it and initialize it with nulls?
> >>> Along those same lines, can I do something like this: *$timing[$x]
> >>> ['Count']++;
> >>> I'm looking for examples, but not finding any on the web. *If someone
> >>> can help, I'd really appreciate it.
> >>> Thank you,
> >>> John
> >> This works:

>
> >> $timing[$x]['Count'] = 0;
> >> $timing[$x]['Start'] = date("g:i:s");

>
> >> $timing[$x]['Count']++;

>
> >> echo var_dump($timing);

>
> >> --
> >> Norman
> >> Registered Linux user #461062- Hide quoted text -

>
> >> - Show quoted text -

>
> > What is the difference between that and something like this:

>
> > * $tables[$x] = array('Acronym' => $table_data[0],
> > * * * * * * * * * * * 'List' * *=> $table_data[1],
> > * * * * * * * * * * * 'Name' * *=> $table_data[2]);

>
> > I'm really looking for a sturcture like this.......is there any
> > difference at all???

>
> Same thing, I just didn't use the 'array' object to create them.
>
> > What about this?

>
> > * * * $summary[$x]['seating'] = array('Seating' => $row[0],
> > * * * * * * * * * * * * * * * * * * * 'Count' * => $row[1]);

>
> > Is the word 'seating' like a section title or something?

>
> > John

>
> --
> Norman
> Registered Linux user #461062
> -Have you been towww.php.netyet?-- Hide quoted text -
>
> - Show quoted text -



So, I'm still a bit unclear what the 'seating' represents.......

Reply With Quote
  #8 (permalink)  
Old 05-27-2008
Jerry Stuckle
 
Posts: n/a
Default Re: Multi Array?

Mtek wrote:
> On May 26, 7:01 pm, Norman Peelman <npeel...@cfl.rr.com> wrote:
>> Mtek wrote:
>>> On May 26, 4:22 pm, Norman Peelman <npeel...@cfl.rr.com> wrote:
>>>> Mtek wrote:
>>>>> Hi,
>>>>> I'm not sure how to do this. Let's say I have an array that looks
>>>>> like this:
>>>>> $timing[$x] = array('Count' => 0);
>>>>> So, basically I've initialized that element of the array with another
>>>>> array item, that being 'Count'. Later, I want to add another item to
>>>>> the array, like this:
>>>>> $timing[$x] = array('Start' => date ("g:i:s"));
>>>>> How would I do that? I'm sure I cannot use the 'array' function more
>>>>> than once........do I need to define it and initialize it with nulls?
>>>>> Along those same lines, can I do something like this: $timing[$x]
>>>>> ['Count']++;
>>>>> I'm looking for examples, but not finding any on the web. If someone
>>>>> can help, I'd really appreciate it.
>>>>> Thank you,
>>>>> John
>>>> This works:
>>>> $timing[$x]['Count'] = 0;
>>>> $timing[$x]['Start'] = date("g:i:s");
>>>> $timing[$x]['Count']++;
>>>> echo var_dump($timing);
>>>> --
>>>> Norman
>>>> Registered Linux user #461062- Hide quoted text -
>>>> - Show quoted text -
>>> What is the difference between that and something like this:
>>> $tables[$x] = array('Acronym' => $table_data[0],
>>> 'List' => $table_data[1],
>>> 'Name' => $table_data[2]);
>>> I'm really looking for a sturcture like this.......is there any
>>> difference at all???

>> Same thing, I just didn't use the 'array' object to create them.
>>
>>> What about this?
>>> $summary[$x]['seating'] = array('Seating' => $row[0],
>>> 'Count' => $row[1]);
>>> Is the word 'seating' like a section title or something?
>>> John

>> --
>> Norman
>> Registered Linux user #461062
>> -Have you been towww.php.netyet?-- Hide quoted text -
>>
>> - Show quoted text -

>
>
> So, I'm still a bit unclear what the 'seating' represents.......
>


It's simply an array index. Nothing more, nothing less.

$summary[$x]['seating'] is an array element; this element in turn is
another array.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #9 (permalink)  
Old 05-27-2008
Mtek
 
Posts: n/a
Default Re: Multi Array?

On May 26, 8:19*pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Mtek wrote:
> > On May 26, 7:01 pm, Norman Peelman <npeel...@cfl.rr.com> wrote:
> >> Mtek wrote:
> >>> On May 26, 4:22 pm, Norman Peelman <npeel...@cfl.rr.com> wrote:
> >>>> Mtek wrote:
> >>>>> Hi,
> >>>>> I'm not sure how to do this. *Let's say I have an array that looks
> >>>>> like this:
> >>>>> $timing[$x] = array('Count' *=> 0);
> >>>>> So, basically I've initialized that element of the array with another
> >>>>> array item, that being 'Count'. *Later, I want to add another itemto
> >>>>> the array, like this:
> >>>>> $timing[$x] = array('Start' *=> date ("g:i:s"));
> >>>>> How would I do that? *I'm sure I cannot use the 'array' function more
> >>>>> than once........do I need to define it and initialize it with nulls?
> >>>>> Along those same lines, can I do something like this: *$timing[$x]
> >>>>> ['Count']++;
> >>>>> I'm looking for examples, but not finding any on the web. *If someone
> >>>>> can help, I'd really appreciate it.
> >>>>> Thank you,
> >>>>> John
> >>>> This works:
> >>>> $timing[$x]['Count'] = 0;
> >>>> $timing[$x]['Start'] = date("g:i:s");
> >>>> $timing[$x]['Count']++;
> >>>> echo var_dump($timing);
> >>>> --
> >>>> Norman
> >>>> Registered Linux user #461062- Hide quoted text -
> >>>> - Show quoted text -
> >>> What is the difference between that and something like this:
> >>> * $tables[$x] = array('Acronym' => $table_data[0],
> >>> * * * * * * * * * * * 'List' * *=> $table_data[1],
> >>> * * * * * * * * * * * 'Name' * *=> $table_data[2]);
> >>> I'm really looking for a sturcture like this.......is there any
> >>> difference at all???
> >> Same thing, I just didn't use the 'array' object to create them.

>
> >>> What about this?
> >>> * * * $summary[$x]['seating'] = array('Seating' => $row[0],
> >>> * * * * * * * * * * * * * * * * * * * 'Count' * => $row[1]);
> >>> Is the word 'seating' like a section title or something?
> >>> John
> >> --
> >> Norman
> >> Registered Linux user #461062
> >> -Have you been towww.php.netyet?--Hide quoted text -

>
> >> - Show quoted text -

>
> > So, I'm still a bit unclear what the 'seating' represents.......

>
> It's simply an array index. *Nothing more, nothing less.
>
> $summary[$x]['seating'] is an array element; this element in turn is
> another array.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -
>
> - Show quoted text -



Seems like a good way to organize things.......

Thanks for the explanation......


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:51 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0