1

This code:

$arr = array(
    'a' => 1,
    'b' => array(
        'c' => 'Hello',
        'd' => [1, 10, 100, 1001]
    ),
);

echo json_encode($arr, JSON_PRETTY_PRINT, 2);

Generates this error:

json_encode() expects at most 2 parameters, 3 given

However the last time I checked, json_encode does accept a 3rd argument.

I want to expand the JSON string by less depths. Ain't the 3rd the solution here? But why does it give this error while PHP doc says it accepts 3?

FYI I'm on WAMP with PHP 5.4.

1
  • 1
    The depth parameter was added in php5.5. It's written in the documentation. Commented Jan 19, 2017 at 7:56

1 Answer 1

1

From the page you link to:

5.5.0 depth parameter was added.

Since you are using PHP 5.4, your version of PHP is too old to support the third argument. PHP 5.4 is also past end of life.

Upgrade to a supported version of PHP. Preferably a 7.x branch as no 5.x branch has a status better than "security fixes only".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.