Skip to main content
Stack Overflow for Teams is now Stack Internal: See how we’re powering the human intelligence layer of enterprise AI. Read more >

All Questions

Tagged with
Filter by
Sorted by
Tagged with
3 votes
1 answer
139 views

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 ...
Jimski's user avatar
  • 1,001
0 votes
2 answers
94 views

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', '...
FigureOfCode's user avatar
1 vote
2 answers
193 views

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. ...
plsssineedheeeelp's user avatar
0 votes
0 answers
64 views

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 ...
Daniel F's user avatar
0 votes
2 answers
319 views

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 ...
Brandon McConnell's user avatar
1 vote
3 answers
389 views

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]...
NulisDefo's user avatar
  • 335
2 votes
1 answer
704 views

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 ...
Aaron Yordanyan's user avatar
2 votes
1 answer
112 views

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 ...
Dave Lovely's user avatar
1 vote
1 answer
92 views

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 ...
Francesco's user avatar
  • 519
-1 votes
1 answer
74 views

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 ...
Born2DoubleUp's user avatar
0 votes
1 answer
109 views

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; ...
aborted's user avatar
  • 4,569
-2 votes
5 answers
1k views

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 ...
Lori's user avatar
  • 130
-1 votes
1 answer
71 views

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['...
Adam Makowski's user avatar
1 vote
0 answers
379 views

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 ...
MAChitgarha's user avatar
  • 4,398
0 votes
2 answers
152 views

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 ...
David Wheatley's user avatar
-3 votes
2 answers
579 views

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 ...
Jerokdeep's user avatar
  • 121
3 votes
2 answers
412 views

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 ...
Dwarf Vader's user avatar
3 votes
2 answers
48 views

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(...
Mike's user avatar
  • 8,887
-3 votes
2 answers
81 views

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 ...
Kivennäisvesi's user avatar
0 votes
0 answers
113 views

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 ...
tj12's user avatar
  • 11
1 vote
1 answer
66 views

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 ...
Troy D's user avatar
  • 401
0 votes
1 answer
97 views

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 ...
Chaosjosh's user avatar
  • 137
0 votes
2 answers
1k views

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; ...
arpak's user avatar
  • 133
0 votes
1 answer
108 views

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){ ...
Dennis's user avatar
  • 949
0 votes
3 answers
2k views

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 ...
Hào Nghiêm Xuân's user avatar
0 votes
1 answer
38 views

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. ...
adamdesign's user avatar
-1 votes
1 answer
391 views

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 ...
user6332864's user avatar
0 votes
1 answer
109 views

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 '...
kurama's user avatar
  • 827
-1 votes
1 answer
184 views

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->...
mmtalon's user avatar
  • 47
-3 votes
1 answer
2k views

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 ...
mshaffer's user avatar
  • 1,013
3 votes
1 answer
386 views

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 ...
Shoelaced's user avatar
  • 891
1 vote
1 answer
109 views

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 ...
LIU YUE's user avatar
  • 2,097
6 votes
4 answers
3k views

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 ...
Marten Koetsier's user avatar
0 votes
1 answer
410 views

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'] = ...
CMarcera's user avatar
2 votes
1 answer
104 views

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."...
mirza's user avatar
  • 5,821
0 votes
1 answer
43 views

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 = '...
Ken Roberts's user avatar
1 vote
4 answers
184 views

I have the following code: function filterUsers(array $setOfAllUsers) { if (empty($setOfAllUsers)) { return array(array(), array()); } $activeUsers = array(); $inactiveUsers = ...
GGio's user avatar
  • 7,673
2 votes
2 answers
396 views

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'; ...
Katrina's user avatar
  • 1,935
2 votes
2 answers
149 views

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']...
Julian's user avatar
  • 147
0 votes
4 answers
2k views

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'; ...
northamerican's user avatar
1 vote
1 answer
206 views

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 ...
ambe5960's user avatar
  • 1,980
2 votes
1 answer
100 views

I'm using this line of code: $var{++$counter} = $results['row']; I've set this up with a goal of creating these variables: $var1 = row 1 $var2 = row 2 $var3 = row 3 Why is it created an array for $...
KDJ's user avatar
  • 309
3 votes
2 answers
237 views

I have a variable $language, which can be: "en", "nl", or "fr".I have 3 other variables $menu_en, $menu_fr and $menu_fr. I have a php page where I want the menu to appear in any of the 3 languages. ...
Paulcraey's user avatar
  • 391
-1 votes
1 answer
32 views

TL;DR: Say I have a global instantiated class $GLOBALS['my_plugin'] = instance(); and I want to use it somewhere else, but I dont know the name 'my_plugin'. Actually I do of course, but my helper ...
Emin Özlem's user avatar
0 votes
1 answer
161 views

I often use the following lines to simplify handling form input. foreach($_POST as $key => $value){ $$key = $value; } This is really handy because you only need there lines and you've got all ...
pocketg99's user avatar
  • 124
0 votes
2 answers
306 views

This is what I want to do: class Contacts { private $_plural = 'contacts'; private $_single = 'contact'; private $_factory = 'contactfactory'; private $_model = 'contact_model'; ...
anche's user avatar
  • 2,904
1 vote
1 answer
127 views

This line of code worked perfectly before I upgraded, now it doesn't: 123: $thisRow[] = displayR(${"sR{$i}S1"}, ${"nR{$i}S1P"}); I get this error: Undefined variable: sR1S1 in script.php on line 123 ...
Codemonkey's user avatar
  • 4,899
0 votes
1 answer
111 views

I have this php code foreach loop inside another foreach what I need is to set all the array value one by one on each loop(red, blue, green, black). I need to change $green in data-percent="<?...
talalalshehri's user avatar
1 vote
1 answer
329 views

Say I have object: function obj() { this.prop1; this.prop2; this.prop3; } and an array of obj's objects = [new obj(),new obj(),new obj()]; I want to easily iterate through each using jquery ...
Jeff's user avatar
  • 480
0 votes
2 answers
638 views

I'm working on a web library for personal use. I thought I'd be all clever and use variable variables to make my library support all request methods easily. I had: $request = '_' . $_SERVER['...
csga5000's user avatar
  • 4,161