PHP - 访问同一阵列中的数组元素 [英] PHP - Accessing array element within the same array
问题描述
有一个阵列,我想打电话给一个值给在同一阵列中的一个关键!结果
我在下面的例子中,我曾试着拨打一个特定的值赋予键默认
在同一阵列内,但没有成功!是否有可能做到这一点在 PHP ?这里是我的数组:
Having an array, I want to call a value giving a key within the same array!
In my following example, I have tried to call a particular value giving the key 'default'
within the same array, but without success! Is it possible to do that in PHP? Here is my array:
$inc_folders = array(
'default' => "def_folder",
'file' => $inc_folders['default'] . "/textfile.txt"
);
调用 $ inc_folders值['文件']
,我希望的结果是以下内容:def_folder / TextFile.txt的
;但我得到一个错误!结果
calling the value in $inc_folders['file']
, I would want the result be the following: "def_folder/textfile.txt"
; but I obtain an error!
请,你能不能帮我解决?结果
非常感谢!
Please, can you help me to resolve that?
Many thanks!
推荐答案
您需要将其分配给一个变量第一;像这样:
You need to assign it to a variable first; like so:
$folder = "def_folder";
$inc_folders = array(
'default' => $folder,
'file' => $folder . "/textfile.txt"
);
或者,构建分两步阵列
Or alternatively, build the array in two steps:
$inc_folders = array(
'default' => "def_folder"
);
$inc_folders['file'] = $inc_folders['default'] . "/textfile.txt";
这篇关于PHP - 访问同一阵列中的数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!