How to fix only variables should be passed by reference error with PHP?

Spread the love

Sometimes, we want to fix only variables should be passed by reference error with PHP.

In this article, we’ll look at how to fix only variables should be passed by reference error with PHP.

How to fix only variables should be passed by reference error with PHP?

To fix only variables should be passed by reference error with PHP, we assign the returned result of explode to a variable before using it.

For instance, we write

$tmp = explode(".", $file_name);
$file_extension = end($tmp);

to call explode with '.' and $file_name to split the $file_name into an array of substrings by the '.'.

Then we call end with $tmp to get the last substring from the $tmp array.

Conclusion

To fix only variables should be passed by reference error with PHP, we assign the returned result of explode to a variable before using it.

Leave a Reply

Your email address will not be published. Required fields are marked *