Questions tagged [variable-variables]

Language feature of PHP: A variable variable takes the value of a variable and treats that as the name of a variable.

Language feature of PHP: A variable variable takes the value of a variable and treats that as the name of a variable.

171 questions
0
votes
5 answers

Use Variable Variable as Array Prefix

Is it possible to use a variable variable as an array prefix? I have a set of arrays with the format $x_settings, and I want to output the values of just one depending on which prefix matches a condition. This is an extremely stripped-down version…
kmgdev
  • 2,607
  • 28
  • 41
0
votes
1 answer

Unable to pass Variable Variable String Value in php

I have a code like this: $values = array('1A', '2B', '3C', '4D', '5E'); $checked = array('1A_check', '2B_check', '3C_check', '4D_check', '5E_check'); $description = array('Description1', 'Description2', 'Description3', 'Description4',…
Neel
  • 9,352
  • 23
  • 87
  • 128
0
votes
1 answer

Variable variabls in php using WAMPserver issue

I am running newest version of WAMPServer on Windows 7 Home Premium. It accesses database (remote) fine, it runs basic PHP fine. My issue is with variable variables. On my godaddy server, the exact code runs fine. When I try to include a file that…
Henry Geiter
  • 103
  • 1
  • 10
0
votes
1 answer

Looping through PHP array in foreach and give each $value a new variable name

I want to take an array, loop it with a foreach loop, and have each array value be sent through a class to get data from a database. This is the code I am currently using: foreach ($unique_category as $key => $value) { $category = $value; …
Runner
  • 115
  • 2
  • 11
0
votes
4 answers

Variable variables created within a for loop

I'd like to change this: if ($week_day == "1") { $day1_hours = $value; } if ($week_day == "2") { $day2_hours = $value; } if ($week_day == "3") { $day3_hours = $value; } if ($week_day == "4") { $day4_hours = $value; } if ($week_day ==…
RobDubya
  • 93
  • 1
  • 1
  • 8
0
votes
0 answers

C# - Web Service property name Dynamic construction

i should construct dinamically the property name (to set it) in a web service invocation using the variables "section" and "fieldName" derived from the two nested foreach (as shown below). I tried with some code found googling "variable variables"…
0
votes
1 answer

What are some alternate ways I can access this php array?

DETAILS I have a separate problem that I am investigating that seems to be related to the way I am accessing arrays. Hence this possibly odd question. I have the following array $response['custom_validation']['agreetotos0']…
TryHarder
  • 2,704
  • 8
  • 47
  • 65
0
votes
2 answers

get_func_argNames and variable variables

I'm writing a method to generate detailed data for logging functions and arguments in debug mode. I previously reproduced the same code in multiple places (bad), but it works just fine (good): function validate_date($date) { if ($condition) …
a coder
  • 7,530
  • 20
  • 84
  • 131
0
votes
0 answers

PHP templating variables - smarty style (or other better style) and unlimited depth

I'm working on a template system that first and foremost needs to be efficient and secondly needs to be easily readable. I have done something nearly identical before, but it involved preg_match_all - hopelessly inefficient. So, say we have the HTML…
Josh Dredge
  • 107
  • 1
  • 1
  • 10
0
votes
3 answers

Variable variables with $_POST

I have a long list of variables with a number at the end. For example address1 and I have all the way up top address14. I want to post these from a form but rather than type out $address1 = $_POST[address1] I would like to create a loop that loops…
Ade
  • 3
  • 1
  • 3
0
votes
1 answer

access to member of object in php with value of parameter?

i want return on of properties of myobject like this code : class myobject{ var $foo = 1; var $bar = 2; function getProperty($Field) { return $this->$Field;// this line have error } } $object = new myobject(); i call method…
aya
  • 1,597
  • 4
  • 29
  • 59
0
votes
1 answer

How do I push an element onto an array who's name is contained in a variable?

I'm making a generic php class which autoloads values into an object from a Database To set properties I use this: $object->$propertyName = $valueFromDB; where the value of propertyName is comes from the mysql field name.. Now I want to push…
user1020317
  • 654
  • 5
  • 22
0
votes
1 answer

Dynamically modify a static variable variable array

Similar to this question Dynamically call a static variable (array) , but for writing to the variables. I'm trying to initialize a couple static arrays in my constructor, but can't figure out how to code their names dynamically. When I try…
Greg
  • 12,119
  • 5
  • 32
  • 34
0
votes
3 answers

PHP - assigning variable in a foreach loop

I have a variable like this $profile = $adapter->getProfile(); Now i'm using it like this $profile->profileurl $profile->websiteurl $profile->etc Now i want to use it in a foreach loop So i created an array like this $data =…
Giri
  • 4,849
  • 11
  • 39
  • 48
0
votes
2 answers

Referencing a multidimensional array's elements based on a string without eval

Alright I'm working with a large multidimensional array which has more information in it than I need and I want to loop through it to filter the data which I'm interested in. Sadly this multidimensional array is produced dynamically and doesn't…
Ultimater
  • 4,647
  • 2
  • 29
  • 43