<?php
$wordFrequencyArray = array();
function countWords($file) use($wordFrequencyArray) { //error here
/* get content of $filename in $content */
$content = strtolower(file_get_contents($filename));
Here is a snippet of a code i am using.
I am getting error on the 3rd line. I have all the matching braces .What might be wrong?
It should be:
$countWords = function($file) use($wordFrequencyArray) {
//...
};
Only anonymous functions may have declare a use
statement, hence the error message warning you that an opening bracket is expected instead of the use
statement.
To circumnavigate having no use
statement, you can either add more parameters and pass it to the function, or in some cases call the variables as global.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With