Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Binlagche's avatar

Parse error: syntax error, unexpected token "if", expecting "]"

I am stuck in my PHP experience and completely a newbie in this help, please. So I don't know how to correct this code, if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {

0 likes
8 replies
tykus's avatar

The problem appears to be before this if statement; an unterminated Array literal perhaps? Can you show us the code in context?

Binlagche's avatar

@tykus so I closed some array above but got a new error instead on this first line, ( syntax error, unexpected token "else" ) that part of the code starts here below } if (!empty($dom[$key]['value']) AND ($dom[$key]['value'][0] == 'h') AND (intval($dom[$key]['value'][1]) > 0) AND (intval($dom[$key]['value'][1]) < 7)) { // headings h1, h2, h3, h4, h5, h6; } if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) { $headsize = (4 - intval($dom[$key]['value']{1})) * 2; $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize; }

devSSI's avatar

Hi @binlagche, as @tykus said error you have has appeared above this if and this part of the error message should've been a hint :) unexpected token "if", expecting "]" ... so instead of "if" you have to close some array or whatever is above :)

Binlagche's avatar

@devSSI so I closed some array above but got a new error instead on the first line, syntax error, unexpected token "else" This is the code } if (!empty($dom[$key]['value']) AND ($dom[$key]['value'][0] == 'h') AND (intval($dom[$key]['value'][1]) > 0) AND (intval($dom[$key]['value'][1]) < 7)) { // headings h1, h2, h3, h4, h5, h6; } if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) { $headsize = (4 - intval($dom[$key]['value']{1})) * 2; $dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize; }

Snapey's avatar

@Binlagche No need to repeat your response. No excuse for not formatting your response.

amitsolanki24_'s avatar
    If (
        !isset($dom[$key]['attribute']['size']) AND
        !isset($dom[$key]['style']['font-size'])
     ) {

Replace AND with &&

Please or to participate in this conversation.