I need some help. in my project i have two variables,
$name = 'john';
$reg = 10;
and from this information i want create a array named $john10
dynamically. like
$john10 = new array();
so please help me.
Although I would discourage doing anything like this in most circumstances, this is how you can do it:
<?php
$name = 'john';
$reg = 10;
${$name.$reg} = array();
Its not a good idea to do this what you want.
If you need something like that name may have different value against different reg, then you can use a 2D array as like:
store[name][reg] = new array();
Hope you analyses that and I redesign your code.
Ok then you can use it though it is not best practice.
<?php
// The very top of your php script
$vars = get_defined_vars();
// Now do your stuff
$name = 'john';
$reg = 10;
// Get all the variables defined in current scope
$john10 = array_diff(get_defined_vars(),$vars);
print_r($john10);
?>