Skip to main content
Inspiring
September 20, 2006
Question

OT: PHP Multidimensional arrays and creating them?

  • September 20, 2006
  • 4 replies
  • 357 views
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
==================



This topic has been closed for replies.

4 replies

Inspiring
September 20, 2006
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/


Inspiring
September 20, 2006
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/
Inspiring
September 20, 2006
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/


Inspiring
September 20, 2006
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/