Foreach Loop with Nested Arrays

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hey Y'all,

I haven't programmed in PHP in quite a while. Could anyone help me
with a foreach loop in a nested array? I have a function which returns
$stock (for an online pricing catalog).

$stock[0] is ( [0] => Item,  [1] => Sale,  ...) an array of column
$stock[1][$i] is ([Item] => SL,  [Sale] => 300, ...) an array of
column headers to value for item $i

What I have to print the header row for the pricing table is:
foreach ($stock[0] as $num => $val) {
    print("<TH>" + $val + "</TH>");

I've also tried ($stock[0] as $x) print($x).

What returns is five zeroes. Not in table cells, just "<TR>00000</

Does anyone have any ideas what I've done?

Thank you in advance,
Taylor Smith

Re: Foreach Loop with Nested Arrays

TSmith wrote:
Quoted text here. Click to load it

print("<TH>" + $val + "</TH>");

This is adding $val to two strings.  Rather, you need

print("<TH>" . $val . "</TH>");

Or, you can even use:


Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline