Jump to content

unexpected "unexpected [" error


libcha

Recommended Posts

Hi,

i wrote this piece of code:

if (mysql_num_rows($res) != 1 || mysql_fetch_assoc($res)["id"] != $correct_id) do_something();

but it doesn't digest the usage of [] operator just after () operator...

(i don't know wheather it's a bug or php is just stupid...)

the only working solution is:

if (mysql_num_rows($res) != 1) do_something();
else {
  $row = mysql_fetch_assoc($res);
  if ($row["id"] != $correct_id) do_something();
}

but i don't want this, because there is the clause do_something() twice...

any better solutions ?

thanks much

Link to comment
https://forums.phpfreaks.com/topic/208519-unexpected-unexpected-error/
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.