0

Following code generates an editor warning for not using $key in the code. Any idea how to avoid this warning? Is there any similar check done by the PHP parses too?

array_walk($services, function(&$value, $key) {
    $value = str_replace('xxx', '', $value);
});
0

2 Answers 2

1

Just remove it.

array_walk($services, function(&$value) {
    $value = str_replace('xxx', '', $value);
});

But note it's an editor warning, it's not PHP warning.

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

Comments

1

From the manual documentation for array_walk:

Typically, callback takes on two parameters. The array parameter's value being the first, and the key/index second.

You can simply omit the $key as it isn't being used inside the callback function.

array_walk($services, function(&$value) {
    $value = str_replace('xxx', '', $value);
});

It's important to note that what you have is perfectly valid PHP code. Just enable error reporting (if you haven't already) and fix any errors the PHP parser throws. There's no reason to change it just because your IDE complains so. In this particular case, it doesn't matter though.

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.