181 questions
3
votes
1
answer
148
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 ...
0
votes
2
answers
98
views
In PHP, how to recurse through a Closure when the variable name holding the anonymous function is a variable-variable
I have a list of about 100 articles, and within each article is a list of clauses. The clauses are a list of varying levels deep.
$clauses = array(
[
'Fields' => ['Clause' => 'clause 1', '...
1
vote
2
answers
196
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. ...
1
vote
2
answers
4k
views
Streamlit dynamic UI to generate dynamic input widgets depending on value from a different input widget
I want to open this post as I can't find anything on the official documentation from streamlit or any resources that mentioned how to do this. After some trial and error I have figured out a way, and ...
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
113
views
How to generate properties of instances of classes in batches?
I have a class named MyClass. I want to generate the attributes k_10sec to k_1d of the instance in batches when generating instances of the class.
How do I modify the code?
bars = ['10sec', '1min', '...
0
votes
2
answers
325
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
1
answer
1k
views
How do I create a dynamic variable based on the row number I am iterating over in an Excel sheet while using openpyxl?
I am trying to iterate over all the rows in an Excel worksheet and set a variable based on the cell that is currently being iterated over. Below is the code that I am using:
import openpyxl
from ...
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 = ...
1
vote
3
answers
391
views
Variable variables as parameters of custom function in usort()
I've been playing around and seeing if I can set up a more dynamic method in PHP.
usort(
$dataset,
function($a, $b){
return strcasecmp($a[$this->parameters], $b[$this->parameters]...
2
votes
1
answer
709
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 ...
2
votes
1
answer
119
views
Variable Variables with array element values syntax
I want to create a session variable but the session variable name I want to be dynamic. So what I need is the proper syntax for a variable name that is a $_SESSION variable.
I have tried the code ...
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
241
views
Variable Variable in django template [closed]
view.py
variable = 'amount'
amount = 200
print(variable) #actual: 'amount' expected: 200
In such case, is it possible to use Variable Variable like PHP?
in php, I could do
$variable = 'amount';
$...
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 ...
-1
votes
1
answer
74
views
Extracting json data using variable variables?
I have a .json file with some data I'm trying to extract. What I need to know is how I would go about making the below variable dynamic.
$MapData['MapData']['0,0']['type'];
What I need to know is how ...
0
votes
1
answer
113
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;
...
-2
votes
5
answers
1k
views
Use list of variables as arguments when defining php function
I am trying to use a list of variables as arguments when DEFINING a function. It seems like it should be straight forward, but no. The callback is easy and I am able to use (...$listOfVariables) to ...
-1
votes
1
answer
75
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['...
1
vote
0
answers
380
views
Undefined variable on defining variable variables
I want to import data from a .json file into a PHP file and dynamically, by using variable variables and a foreach loop, define new variables. However, PhpStorm doesn't recognize my variables and give ...
0
votes
2
answers
153
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
584
views
Using str_replace in variable variable in php
I have a suitecrm implementation where I would like to print a numbers in words in an invoice. The number is currency formatted, so it comes with commas (,). While I try to replace the commas with ...
3
votes
2
answers
415
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
52
views
Variable properties on a variable method
I'm using a third-party package which manipulates images. For basic conversions it accepts a single value:
$image = $this->addMediaConversion('thumb');
$image->width(100);
$image->height(...
-3
votes
2
answers
82
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
0
answers
113
views
How do you set a static variable variable in object?
I have an object Obj with a method sql() that creates SQL queries to update a database. The tables in the database have unique names for their ID fields. My objective is to be able to define the table ...
0
votes
2
answers
119
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'
...
17
votes
5
answers
12k
views
How can I select a variable by (string) name?
I want to return a pre-determined list from my function, based on the string input.
def get_ext(file_type):
text = ['txt', 'doc']
audio = ['mp3', 'wav']
video = ['mp4', 'mkv']
return # ...
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
1
answer
97
views
Calling Class property using variables in Zend
I am creating partials where an items property names are passed from an array to access the values of those properties but I receive an error saying Undefined property of Namespace\Entity::$variable ...
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
2
answers
1k
views
auto add number at end of variable
i have this variable
$n= "";
it can be 1 or 2 example: $n= "1"; or $n= "2";
so i want $number to be changed to $number1 or $number2 so it will get 1 or 2 from $n
$live = ($number1-$r3) / 60;
...
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
3
answers
2k
views
php: How to get element in array by index using variable-variables
If I have:
<?php
$params=[
[
'string'
]
];
//params get from $this->params()->fromPost();
$abc='params[0][0]';//$abc dynamiccly
I cannot access $params[0]
How to get string ...
0
votes
1
answer
39
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. ...
-1
votes
1
answer
391
views
How to use foreach to loop through a file with variable variable?
The following PHP code using foreach does not seem to work. I believe it has to do with "<a href='/$value/access'>".
I've shared the entire codebase.
Does anyone know what is wrong with my ...
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 '...
-1
votes
1
answer
184
views
Class & Object Scope for Variable Variables in PHP
Question 1) Why is the Variable/variable $this->$template not visible to parse_and_return(), lines 42-50, but visible to $this->fetch, lines 456-472. I thought parse_and_return and $this->...
-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 ...
3
votes
1
answer
386
views
Dynamically numbered variables in foreach loop
I have an array full of sub-arrays, which in turn are full of source names and their website URLs, such as The New York Times and http://newyorktimes.com.
I'm displaying a list of links where the ...
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 ...
6
votes
4
answers
3k
views
Variable variables handling order: changes in PHP 7
With the new PHP 7.0.0 out now, I'm a bit worried about the changes in evaluation order of the so-called 'variable variables'.
On this page, under 'Changes to variable handling', a table is displayed ...
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'] = ...
2
votes
1
answer
106
views
How to reach variable variables which has spaces? [duplicate]
I was curious about how to reach variable variables which contain spaces or special chars.
Is there a way to do ?
<?php
$first_day = "monday";
$$first_day = "first day of the week";
echo $monday."...
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 = '...
1
vote
4
answers
190
views
Using variable variables to populate array results in error
I have the following code:
function filterUsers(array $setOfAllUsers) {
if (empty($setOfAllUsers)) {
return array(array(), array());
}
$activeUsers = array();
$inactiveUsers = ...
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';
...
2
votes
2
answers
150
views
Variable variable for array
I have defined an array $array[1][1][test]="hello world". I would like to get this value by using variable variables. I have tried this, without success:
$var1="array";
$var2="[1][1]";
$var3="['test']...
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';
...
1
vote
1
answer
206
views
Dynamically append indexes to variable
So I have arrays of different lengths
pathes= array(array('f1e9'),
array('c0d9', '0', 'form_values', '6e13')
);
For each path I would like to use each value as an index to scan a ...