views:

17

answers:

1

Hi there,

I'm new to programming and I'm tackling arrays. I thought I had multi-dimensional arrays figured out but I guess I don't. Here's the code I'm working on:

$loopcounter = 0;    
while ($myrow = mysql_fetch_array($results)) {
//...other stuff happens...
$allminmax[$loopcounter][] = array("$myrow[3]","$currentcoltype","$tempmin","$tempmax");
$loopcounter++;

}

This chunk of code is supposed to create an array of four values ($myrow[3], currentcoltype, tempmin, tempmax) and insert it into another array every time the loop goes through. When I do this:

echo implode($allminmax);

I get:

ArrayArrayArrayArrayArrayArrayArrayArrayArray

Do I need to implode each array before it goes into the master array? I really want to be able to do something like $allminmax[0][4] and get the $tempmax for the first row. When I try this now nothing happens. Thanks -- any help is appreciated!

A: 

It looks like you should either use [$loopcounter] or [], but not both. You also should drop the quotes. They're unnecessary and in the case of "$myrow[3]" they interfere with the variable interpolation.

$allminmax[] = array($myrow[3], $currentcoltype, $tempmin, $tempmax);

By the way, arrays are zero-indexed, so to get $tempmax for the first row it'd be $allminmax[0][3] not $allminmax[0][4].

Also, a better way to display the contents of your array is with print_r or var_dump. These will display arrays within arrays while a simple echo will not.

var_dump($allminmax);
John Kugelman