-2

Am running PHP Version 5.2.17 i got this error on below code

        // member information
        $json = json_encode([
            'email_address' => $email,
            'status'        => '',
        ]);

Am stuck don't know what wrong with my code, any help is appreciated

5
  • 1
    That syntax is invalid for PHP 5.2. Commented Dec 31, 2016 at 20:18
  • Thanks, but am little new to PHP stuff, how do i replace that code to higher version? Commented Dec 31, 2016 at 20:21
  • Instead of [ use array( and for the closing use ). php.net/manual/en/function.array.php Commented Dec 31, 2016 at 20:22
  • Please upgrade your version of PHP to a modern version... PHP5 is end of life now, and PHP 7.1 is the current latest version Commented Dec 31, 2016 at 20:26
  • Thanks, just tried below answers and it work for me like magic Commented Dec 31, 2016 at 20:49

2 Answers 2

0

You cant use short array syntax [] in PHP < 5.4

So you have to do it the old way array( )

http://php.net/manual/en/migration54.new-features.php

For your specific case just change it to this

    $json = json_encode(array(
        'email_address' => $email,
        'status'        => '',
    ));
Sign up to request clarification or add additional context in comments.

3 Comments

@chris85 - TBH I'm not sure how to, lol
NM- figured it out... learn something new every day.
Under the tags you should have a close link on the question. stackoverflow.com/help/privileges/close-questions
0

I think your syntax is not valid anymore. Try this:

$arr = array('email_address' => $email, 'status' => '');
$json = json_encode($arr);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.