Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

OT: PHP Multidimensional arrays and creating them?

LEGEND ,
Sep 20, 2006 Sep 20, 2006

Copy link to clipboard

Copied

I have a process that is generating successive sets of data, where each set
consists of three 'fields', or separate values, e.g.,

set1 = 'a', 'b', and 'c'
set2 = 'd', 'e', and 'f'

As each set is generated, I want to save it in an ongoing array so that when
the process is finished all of the data is contained within that array as
successive 'rows'.

Can someone give me a nudge for this in PHP, please?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================



TOPICS
Server side applications

Views

325
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2006 Sep 20, 2006

Copy link to clipboard

Copied

Murray *ACE* wrote:
> Can someone give me a nudge for this in PHP, please?

Shove... :)

You'll have to be a bit more precise in saying how your sets are
created. In general terms, though, just create a loop and add the items
using square bracket notation:

$row = array();
while (condition is true) {
$row[] = $set;
}

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2006 Sep 20, 2006

Copy link to clipboard

Copied

Oops <stumble>....

Hmm - OK.

Here's what I'm doing now:

$i=0;
$myarray[$1][0]=dataitem1;$myarray[$i][1]=dataitem2;$myarray[$i][2]=dataitem3;
$i++;

and I'm looping through this for a specified number of iterations.

Is that the most efficient way?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:eerm14$1bm$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> Can someone give me a nudge for this in PHP, please?
>
> Shove... :)
>
> You'll have to be a bit more precise in saying how your sets are created.
> In general terms, though, just create a loop and add the items using
> square bracket notation:
>
> $row = array();
> while (condition is true) {
> $row[] = $set;
> }
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2006 Sep 20, 2006

Copy link to clipboard

Copied

Murray *ACE* wrote:
> $i=0;
> $myarray[$1][0]=dataitem1;$myarray[$i][1]=dataitem2;$myarray[$i][2]=dataitem3;
> $i++;
>
> and I'm looping through this for a specified number of iterations.

$myarray = array();
for ($i = 0; $i < $number_of_iterations; $i++) {
array_push($myarray[$i], dataitem1, dataitem2, dataitem3);
}

http://www.php.net/manual/en/function.array-push.php

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2006 Sep 20, 2006

Copy link to clipboard

Copied

LATEST
Ahhh - eggsellect. <stands up>

Thanks!

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:eerob7$49l$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> $i=0;
>> $myarray[$1][0]=dataitem1;$myarray[$i][1]=dataitem2;$myarray[$i][2]=dataitem3;
>> $i++;
>>
>> and I'm looping through this for a specified number of iterations.
>
> $myarray = array();
> for ($i = 0; $i < $number_of_iterations; $i++) {
> array_push($myarray[$i], dataitem1, dataitem2, dataitem3);
> }
>
> http://www.php.net/manual/en/function.array-push.php
>
> --
> David Powers
> Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> http://foundationphp.com/


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines