Variable Variables

Variable Variables

Medium PHP PHP Variables 17 views
Explanation Complexity

Problem Statement

Input: name value. Create a variable with that name and print it back.

Input Format

One line: name value.

Output Format

One line: value.

Example

city Pune
Pune

Constraints

name has letters only.

Input / Output Format

Input Format
One line: name value.
Output Format
One line: value.
Constraints
name has letters only.

Examples

Input:
city Pune
Output:
Pune

Example Solution (Public)

PHP
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$tokens=preg_split('/\\s+/', $inputText, 2);
$name=$tokens[0] ?? '';
$val=$tokens[1] ?? '';
$$name=$val;
echo $$name;
?>

Official Solution Code

<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$tokens=preg_split('/\\s+/', $inputText, 2);
$name=$tokens[0] ?? '';
$val=$tokens[1] ?? '';
$$name=$val;
echo $$name;
?>
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.