Excuse for my English, I am Italian and I try to learn PHP.
You would know me what does not go in this
$a[0][0] = "a";
$a[0][1] = "b";
$a[1][0] = "y";
$a[1][1] = "z";
foreach($a as $v1) {
foreach ($v1 as $v2) { // line 42
print "$v2\n";
}
}
Warning: Invalid argument supplied for foreach() in /usr/local/apache2/htdocs/test/foreach.php on line 42
statement foreach ... help!!
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
That's strange, I ran your code and it works fine for me. Perhaps something else in your code is not working as expected, for debugging try:
You should get output that looks like:
Mac
Code: Select all
$a[0][0] = "a";
$a[0][1] = "b";
$a[1][0] = "y";
$a[1][1] = "z";
echo '<pre>$a contains: ';
print_r($a);
echo '</pre>';
foreach($a as $v1) {
echo '<pre>$v1 contains: ';
print_r($v1);
echo '</pre>';
foreach ($v1 as $v2) { // line 42
print "$v2\n";
}
}Code: Select all
$a contains: Array
(
ї0] => Array
(
ї0] => a
ї1] => b
)
ї1] => Array
(
ї0] => y
ї1] => z
)
)
$v1 contains: Array
(
ї0] => a
ї1] => b
)
a b
$v1 contains: Array
(
ї0] => y
ї1] => z
)
y z- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK