Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

variables
php
communitycreator

What is the get_defined_vars() method in PHP?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The get_defined_vars method can be used to get the list of defined variables in the current scope.

The defined variables include:

  • User-defined variables.
  • Environment variables.
  • Server variables.

Syntax


get_defined_vars(): array

Returns

This function returns a multidimensional array as a result.

Code

<?php
$a = 10;
$b = 20;
$defined_var = get_defined_vars();
var_export($defined_var);
?>

Explanation

In the code above, we created two variables, a and b, and called the get_defined_vars method to get the list variables that are defined in the scope. This will return a multidimensional array with all the defined variables.

RELATED TAGS

variables
php
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring