181 questions
3
votes
1
answer
139
views
How to convert a string in an array to variable using the array index in PHP [duplicate]
Let's say I have an array_1 containing a string which is a name of another array_2. And now I would like to convert the array index into a variable containing the array_2.
I have the following working ...
1
vote
2
answers
193
views
Variable variable is not accessible within callback scope while using arrow function syntax (Warning: Undefined variable)
I need to use a variable variable for defining a lambda function inside of the callback of array_map(). I get an "Undefined variable" WARNING for the variable that I am referencing. ...
0
votes
0
answers
64
views
How can I echo a php variable that's INSIDE a php string variable?
I've got a database full of text fields, all of which contain WITHIN them the characters $myvariable.
When I retrieve such text field and save it as a php variable, say as $myDBtext, I can definitely ...
0
votes
2
answers
319
views
PHP variable variable not overriding original variable
I am trying to override some variables in my PHP file using variable variables, but I am getting unexpected results, where the original value is never overwritten, but where the new variable-variable ...
0
votes
3
answers
3k
views
How to check if function exists inside another function using Javascript
I`m trying to build an function that load script on-demand. That is my current code:
function loadScript(src, name = null)
{
var dfd = jQuery.Deferred();
if (name === null) {
name = ...
2
votes
1
answer
704
views
Trying to access $_SERVER(or any global) variable from string name [duplicate]
Today I met such a terrible situation.
It seems this bug is related to PHP.
I'm trying to access to $_SERVER or another super global variables but from string name.
This version of implementation is ...
1
vote
1
answer
92
views
How can I access a specific depth of an associative array with variable variables
I've been hitting my head on this problem for some time now. I am working on a piece of software that creates a tree from a MySQL result checking for changes between each row to decide where in the ...
0
votes
1
answer
44
views
How would I use the contents of one variable to create the name of another? [duplicate]
I'm creating code that creates new user identifications for users, and then adds all their account details to a dictionary and then adds this dictionary to another dictionary of all the accounts.
My ...
0
votes
1
answer
110
views
Passing variable variable into closure throws a parse error?
I just noticed that if you try to put a variable variable into a use list of a closure, it throws a parse error. Example code:
foreach ($array as $key => $item) {
$$key = $item->something;
...
-1
votes
1
answer
71
views
How to for loop 10 times values in single string using comma?
How I can use for loop PHP to create same result in $d4_c_d_v as below?
Note: $d4_c_d_v must end without comma at the end.
$d4_c_d_v =
$g_demographics_value_0['id'] .','.
$g_demographics_value_1['...
0
votes
2
answers
152
views
How can I make a variable's name from another variable AND string?
Say I had the variable $foo which has a value of "bar" and I wanted to make a variable variable from it, but also append the string "123" to it, so that the variable name is $bar123. How would I do ...
3
votes
2
answers
413
views
Using eval() in the code, and how would you avoid it?
In my code, I want to try fetching $_POST or $_GET variables, and unsetting them as soon as they were requested once.
This function returns the method used, which is simple enough. Unfortunately I ...
-3
votes
2
answers
81
views
PHP: How to increase a number in variable that contains both text and the number [duplicate]
This is quite a stupid question. I want to find out how to increase a number in the end of the variable:
$Coffee1 = "black";
$Coffee2 = "brown";
$Coffee3 = "gray";
echo $Coffee1; => black
...
0
votes
2
answers
118
views
How do I split and reconstruct a variable name while holding its original value
Is it possible to split variables that have already been assigned values, and re-piece them back together to hold those same previous values?
For Example:
URLs.QA.Signin = 'https://qa.test.com'
...
1
vote
1
answer
67
views
Are different PHP variable variables that resolve to the same variable name the same variable?
Let's say I have an array of strings that I use to create variable variables:
$var_arr = ["item1", "item2", "item3"];
foreach ($var_arr as $item) {
$$item = array();
}
Then elsewhere in my code I ...
0
votes
2
answers
701
views
Javascript dynamically create variables from array
just started to dabble with Javascript so I'm sorry if this is a basic question. I have an array of keys:
keys = ['fruits','vegetables','fats','meats']
I want to dynamically create a Map for each of ...
0
votes
1
answer
108
views
Dynamic class creation in php
I'm trying to do a bit of php magic in one line with instantiating a class, but it seems the parser wont allow me. Example:
class Test{
private $foo;
public function __construct($value){
...
0
votes
1
answer
38
views
PHP - returning a variable variable from a function scope
Is there a way to return a variable variable from a function?
This is what I tried:
function varvar($num){
$var = "foo".$num;
return $$var;
}
varvar(3);
echo $foo3;
But nothing prints out. ...
0
votes
1
answer
109
views
PHP and variable variables ($$) syntax
Before upgrading to PHP 7, I had this code and it returned true
var_dump(isset($$_SESSION['payment']) );
var_dump(is_object($$_SESSION['payment']));
var_dump($_SESSION['payment']); // string '...
-3
votes
1
answer
2k
views
Using R, how to reference variable variables (or variables variable) a la PHP
Using R stats, I want to access a variable variable scenario similar to PHP double-dollar-sign technique: http://php.net/manual/en/language.variables.variable.php
Specifically, I am looking for a ...
1
vote
1
answer
109
views
Use variable variables with PHP's Superglobal arrays outside of function and class
I'm beginner of PHP, I found a Warning says:
Please note that variable variables cannot be used with PHP's Superglobal arrays within functions or class methods.
So, does it mean I can use variable ...
0
votes
1
answer
410
views
Using a variable variable in an object property in PHP
I've set a few variables:
$field = "XYZ";
$block_hi = $field."_hi";
$block_lo = $field."_lo";
Then I have an object with properties that have the name of my above variables:
$obj->XYZ_hi['val'] = ...
0
votes
1
answer
43
views
php variable variables to access property of an object
I want to store an property->object name in a table and access in code.
What is the proper way to accomplish the following.
$patient = new stdClass();
$patient->patient_number = '12345';
$cls = '...
2
votes
2
answers
396
views
PHP - Difference in creating variable variables with brackets or double dollar signs?
From what I can tell in the PHP Manual, it doesn't seem like there is much difference between defining a variable variable with double brackets or double dollar signs.
$foo = 'hello';
$$foo = 'hi';
...
0
votes
4
answers
2k
views
PHP variable not working when referenced with '$'
I'm trying to convert a PHP variable to a JS variable using a little helper function that uses variable variables. To simplify, here is what I'm trying to accomplish:
$project_key = 'project 1';
...