问题标签 [variable-variables]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
php - 使用变量变量作为数组前缀
是否可以使用变量变量作为数组前缀?我有一组格式为 的数组$x_settings
,我想根据哪个前缀与条件匹配来输出一个数组的值。
这是更复杂代码的极其精简的版本,因此感谢您的放纵:
如您所见,我尝试使用${$env}_settings[]
,但这给了我一个 PHP 错误:
意外的“_settings”(T_STRING)
可能的?
php - foreach 循环中的 PHP 变量变量不起作用
如果我能让它工作,这是一个绝妙的小技巧——我有来自数十个表的数百个数据列,分布在十几个数据表单(它们是 HTML 打印表单)中,它们都是带有嵌入式 php 变量的 html。很正常。然而,客户需要知道哪个领域在哪里——这是一个非常好的问题。
那我做了什么?我研究了一个解决方案,该解决方案允许来自数据库的键数组放弃它们的列名。一个绝妙的举动!除了我需要通过可变变量来完成,猜猜看,它们在 foreach 循环中不起作用。
这是代码
如您所见,我想要一个简单的终止开关机制来剪切和粘贴不再显示真实数据的键数组,而是显示(粉红色)列名和(可能)表名也。已经有很多代码,如果它可以工作,这将是一个绝妙的选择
编辑:这是 PHP 错误:
编辑:代码实际上已经有效:修复是为了测试 is_array()
会起作用,而不是仅仅
php - php和带数组的变量变量
尝试最终得到 7 个数组($mon、$tue、$wed、$thu、$fri、$sat、$sun),在给定初始数组 $hours 的情况下,一天中的每个小时都包含 0 或 1 的值。$hours 只是一个发布的数组,其中包含用户选择的一周中每一天的小时数。
我相信问题在于我使用变量变量($$day),因为我的工作日数组都返回 null($mon、$tue、$wed、$thu、$fri、$sat、$sun)。任何援助将不胜感激。
编码 :
编辑 - 使用的结束解决方案:
对我的脚本的其他方面进行一些必要的更改。
php - PHP Variable object properties
I understand the concept of variable variables in PHP. According to my understanding of variable variables in PHP the following code:
Will generate the output as:
But I am finding it difficult to understand the case of variable object properties
Say I have a class called foo with a single property as follows:
Now, creating the instance of the class foo and using the concept of variable variables the following code:
will output:
Up till everything is fine, but when I include a property having an array value it gets messed up for me. Say for example I add another property with array value to the class foo and now the class looks like:
Now When I create the instance of the class foo and try to read the property $arr[1] as follows:
Which outputs:
and the output looks weird to me. I mean how does $foo->$arr[1] resolves to the propery $r in the class foo ?
Shouldn't doing $foo->$arr resolve into $foo->arr[1] (Note: There is no dollar sign) giving the output:
How does this happen?
I am aware that doing $foor{$arr}[1] outputs "I am B."
My question is why does $foo->$arr doesn't resolve into $foo->arr ? Given that the variable $arr is holding the value 'arr' ?
A note to admins/supervisors: This question is not a duplicate; I have tried searching for the similar questions but none of it answered what I need to know.
php - 变量变量不起作用
我有一些似乎不起作用的代码。我正在使用一个表单来发布一个值(绿色、蓝色、红色等),并使用该发布值作为变量名的一部分在数据库中查找某些内容。
它正在查找列“hasgreen”,在本例中为 INT 4。问题是,它告诉我 $rowmine['hasgreen'] 为 NULL,因此我被踢回“mine.php”。我不确定问题是什么,也许是在变量名中使用了\'?
php - 数组名称中的大括号变量,PHP
我知道这里有很多类似的问题,我想我已经全部阅读过了。我的问题是我试图遍历数组列表并从每个数组中获取一个值。阵列已由第三方设置,我无权配置接收它们的方式。这是我到目前为止所拥有的:
我已经尝试了很多(很多!)更多我不会包括在内的组合。我也尝试将 $i 转换为字符串。有一段时间我一直在反对这个。
提前感谢您的帮助。
javascript - JavaScript中的变量?
在 PHP 中,我可以处理变量变量,我想知道我是否可以在 JavaScript 中做同样的事情。
我想创建一个新对象,其名称基于变量的值。
有没有更短的方法来做这件事而不使用eval()
?就像是:
php - PHP 变量变量混淆
我正在使用while
循环并mysql_fetch_array
在数据库的页面上显示信息。如何为页面上回显的某些单选按钮元素提供变量名称,然后在$_POST
提交表单时将这些变量名称用于单选按钮作为变量?
这是代码:
php - 将变量变量设置为数组键
我不知道如何问这个问题,但这里是:
这是&
字符用于“变量”的东西吗?
或者也许eval
?
php - Looping variable variables, illegal string offset
I keep getting
Warning: Illegal string offset 'type' in ... on line ...
I've tried following the answers here Illegal string offset Warning PHP
by doing something like
#xA;but it still gives errors, I think it might have something to do with variable variables (it's the first time I am using them. Below is my code:
#xA;I won't like to create arrays T1, T2 ... T15, with the following values ['type'], ['hidden'], ['require'], ['list']
.