How to Pass Value by Reference in Function?

How to Expose and Route to a Resource?
How to Expose and Route to a Resource?

Problem:- How to Pass Value by Reference in Function? You want to pass a variable to a function and have it retain any changes made to its value inside the function.

How to Pass Value by Reference in Function?
How to Pass Value by Reference in Function?

Solution – Pass Value by Reference in Function

<?php
function wrap_in_html_tag(&$text, $tag='em'){
	$text = "<$tag>$text</$tag>";
}
?>

How it Works?

Passing a variable to a function by reference allows you to avoid the work of returning the variable and assigning the return value to the original variable. It also useful when you want to function to return a Boolean success value of true and false.

इसे भी पढ़े – Photoshop में Blur Tool और Dodge Tool

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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