Jump to content

[SOLVED] foreach, invalid argument?


Ryokotsusai

Recommended Posts

Hi,

 

I have a small function that is supposed to retrieve a list of links from a database and then build the link list from what it retrieves, but for some reason I cannot get it to work.

 

It errors out on the "foreach" line saying:

 

Warning: Invalid argument supplied for foreach() in /home/revrocom/public_html/character/cnt/cnf/lnk.php on line 52

 

but when i printed $lin it contained the array

 

The actual page can be found here

 

and here is the function where it errors followed by what the print_r outputs:

 

function links($area,$tabs = 0){


global $LINK;

$i = 0;
$f = count($LINK[$area]); // = 6
$t = "	";

if($tabs > 0) {

	while($tabs > 0) {

		$tab .= $t;
		$tabs--;

	}

} else {

	$tab = "";

}

while($i <= $f) {

	$end = $tab."<li><a ";
	$lin = $LINK[$area][$i];

	foreach($lin as $key => $val) { // Line 52

		$end .= ($val != "" && $val != NULL && $key != 'text') ? $key."=\"".$val."\" " : "";
		$end .= ($val != "" && $val != NULL && $key == 'text') ? ">".$val."</a></li>" : "";

	}

	print_r($lin);
	$i++;
	unset($lin);

}

echo $end;

}

/*
print_r output:

Array
(
    [href] => http://char.rev-ro.com/cnt/cp/home/
    [title] => Home Page
    [id] => 
    [class] => 
    [text] => Home
)
Array
(
    [href] => http://char.rev-ro.com/cnt/cp/user/
    [title] => User Administration
    [id] => 
    [class] => 
    [text] => User Control
)
Array
(
    [href] => http://char.rev-ro.com/cnt/cp/admin/
    [title] => Administrative Control
    [id] => 
    [class] => 
    [text] => Admin Control
)
Array
(
    [href] => http://char.rev-ro.com/cnt/cp/site/
    [title] => Site Control
    [id] => 
    [class] => 
    [text] => Site Control
)
Array
(
    [href] => http://char.rev-ro.com/cnt/cp/stats/
    [title] => Server Statistics
    [id] => 
    [class] => 
    [text] => Stats
)
Array
(
    [href] => http://char.rev-ro.com/cnt/cp/help/
    [title] => Help / Contact Us
    [id] => 
    [class] => 
    [text] => About
)

*/

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.