OT: PHP Multidimensional arrays and creating them?

OT: PHP Multidimensional arrays and creating them?

Post by Murray *AC » Thu, 21 Sep 2006 21:01:16


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.yqcomputer.com/ - Template Triage!
http://www.yqcomputer.com/ , Tutorials & Resources
http://www.yqcomputer.com/ - DW FAQs, Tutorials & Resources
http://www.yqcomputer.com/ (MM) Technotes
==================
 
 
 

OT: PHP Multidimensional arrays and creating them?

Post by David Powe » Fri, 22 Sep 2006 00:16:50


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://www.yqcomputer.com/

 
 
 

OT: PHP Multidimensional arrays and creating them?

Post by Murray *AC » Fri, 22 Sep 2006 00:40:05

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.yqcomputer.com/ - Template Triage!
http://www.yqcomputer.com/ , Tutorials & Resources
http://www.yqcomputer.com/ - DW FAQs, Tutorials & Resources
http://www.yqcomputer.com/ (MM) Technotes
==================
 
 
 

OT: PHP Multidimensional arrays and creating them?

Post by David Powe » Fri, 22 Sep 2006 00:56:21


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

http://www.yqcomputer.com/

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

OT: PHP Multidimensional arrays and creating them?

Post by Murray *AC » Fri, 22 Sep 2006 01:05:24

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.yqcomputer.com/ - Template Triage!
http://www.yqcomputer.com/ , Tutorials & Resources
http://www.yqcomputer.com/ - DW FAQs, Tutorials & Resources
http://www.yqcomputer.com/ (MM) Technotes
==================