Jump to content

unknown foreach error


ratcateme

Recommended Posts

Hi i have a script with this foreach i got an "unexpected $end" i commented out all my script and traced the error to this code block

foreach($ip_x as &$value){
echo $value;
}

i added a print_r($ip_x) and it showed me ip_x is a proper array

i can comment out this block and the rest of my script works fine

 

Scott.

Link to comment
https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/
Share on other sites

here is the full code it is to check for a valid IP

<?php
$ip_error=false;
$ip_x=explode('.',$ip);
if(count($ip_x)==4){
print_r($ip_x);
foreach($ip_x as $value){
	if(!($value>0 && $value<255)){
		$error=3;
	}
	echo $value;
}
}else{
$error=4;
}
?>

 

 

Scott.

 

Link to comment
https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467484
Share on other sites

Post the actual error message and the complete code it corresponds to.

 

If the error is "unexpected $end", that usually means that there is a mis-match in {}. Neither of the posted pieces of code results in that error, so either the posted code is not complete or the error is different.

Link to comment
https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467521
Share on other sites

I have COMMENTED out all the code but this

<?php
$ip_x=explode('.',$ip);
if(count($ip_x)==4){
	print_r($ip_x);
	//for($i=0;count($ip_x)>$i;$i++){
	foreach($ip_x as $number){
`			if(!($number>0 && $number<255)){
			$error=3;
		}
		echo $number;
	}
}else{
	$error=4;
}
?>

and i get this error

Parse error: syntax error, unexpected $end in /var/www/html/dyndns.php on line 145

i then coppied only that code into a blank php file

and got this

Parse error: syntax error, unexpected $end in /var/www/html/a.php on line 15

 

Scott.

Link to comment
https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467983
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.