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: $...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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??? |
|
|||
|
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 |
|
|||
|
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 ================== |
|
|||
|
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?- |
|
|||
|
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....... |
|
|||
|
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 ================== |
|
|||
|
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...... |