Pass by Value

This lesson introduces the pass by value method of passing a parameter to a function.

PHP allows us to pass arguments into a function in two ways:

  • Pass by Value
  • Pass by Reference

Let’s take a look at pass by value method.

Arguments Passed by Value #

On passing arguments using pass by value, the value of the argument gets changed within a function, but the original value outside the function remains unchanged. That means a duplicate of the original value is passed as an argument.

Example: Cube of a Number #

Consider the following program that accepts a number and prints its cube:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy