我已经声明Javascript数组,然后我可以通过键访问它们,但是很久以前,我忘记了我是怎么做到的.
基本上,我有两个要存储的字段,一个唯一的键及其值.我知道有办法做到这一点..类似于:
var jsArray = new {key: 'test test', value: 'value value'},
new {key: 'test 2', value: 'value 2'};
Run Code Online (Sandbox Code Playgroud)
并访问如下:
value = jsArray[key]
Run Code Online (Sandbox Code Playgroud)
有人能提醒我吗?
为什么我不能使用table.sort对具有关联索引的表进行排序?
我一直用PHP制作一个IRC机器人.我给了不同用户特定的访问级别在0到5之间.0是访客,5是管理员.
我一直在尝试编写一个命令,当用户访问它时,它会向他们发送一个允许他们使用的命令和语法列表.
到目前为止,我有类似的东西
$array = array
(
"5" => $commands = array
(
"test" => $test2 = array
(
"trigger" => "!test",
"descrip" => "Just testing."
)
"test2" => $test3 = array
(
"trigger" => "!lol",
"descrip" => "another test."
)
)
);
Run Code Online (Sandbox Code Playgroud)
我不知道如何循环通过它 if ($accessLevel == 5) then show commands for $array[5(and below)]
最后我希望它发送出去 $array[5][command][trigger] : $array[5][command][descrip]
我不一定需要你为我编码,只是向正确的方向推进会有所帮助.
我有像这样的关联数组
array
{
[company 1]=>array
(
[1981] => 1
[1945] => 3
)
[company 2]=>array
(
[1990] => 18
[2005] => 13
)
[company 3]=>array
(
[1950] => 6
[2012] => 9
)
}
Run Code Online (Sandbox Code Playgroud)
我想获得最低和最高的键,即 1945 年和 2012 年。我怎样才能做到这一点?我已经搜索过 stackoverflow 并且关联数组的 Hightest 值 是最接近的可能性,但它给出了最小值和最大值,我想要最小值和最大值键。
**我不想使用foreach循环**
任何人都可以帮助我循环通过递归数组和使用PHP创建多级嵌套列表的逻辑.我在超越顶级列表节点方面并不是很成功.
请看下面的数组:
Dump => array(6) {
[0] => array(5) {
["id"] => string(1) "1"
["label"] => string(13) "address types"
["slug"] => string(17) "admin/addresstype"
["parent_id"] => string(1) "0"
["has_children"] => bool(false)
}
[1] => array(5) {
["id"] => string(1) "3"
["label"] => string(9) "dashboard"
["slug"] => string(15) "admin/dashboard"
["parent_id"] => string(1) "0"
["has_children"] => bool(false)
}
[2] => array(6) {
["id"] => string(1) "5"
["label"] => string(16) "feature category"
["slug"] => string(21) "admin/featurecategory"
["parent_id"] => string(1) "0"
["has_children"] => bool(true)
["children"] …Run Code Online (Sandbox Code Playgroud) 我有这个文件
affaire,chose,question
chose,emploi,fonction,service,travail,tâche
cause,chose,matière
chose,point,question,tête
chose,objet,élément
chose,machin,truc
Run Code Online (Sandbox Code Playgroud)
我想有一个像这样的关联数组:
affaire => chose, question
cause => chose, matière
chose => emploi, fonction, service, travail, tache, point, question, tete, objet élément, machin, truc
Run Code Online (Sandbox Code Playgroud)
甚至更好,每当我找到一个新单词时,将单词保存为键,将上下文(左或右和右)保存为值...例如:
affaire => chose, question
cause => chose, matière
chose => affaire, question, cause, matière, emploi, fonction, service, travail, tache, point, question, tete, objet élément, machin, truc
Run Code Online (Sandbox Code Playgroud)
目前我正在尝试以这种方式创建关联数组:
$in = "test.txt";
$out = "res_test.txt";
open(IN, "<", $in);
open(OUT, ">", $out);
%list = '';
while(defined($l = <IN>)){
if ($l =~ /((\w+),(.*))/){ …Run Code Online (Sandbox Code Playgroud) 所以我有这个要输入和关联数组:
47 SPRINGGREEN2
48 SPRINGGREEN1
49 MEDIUMSPRINGGREEN
50 CYAN2
51 CYAN1
52 DARKRED
53 DEEPPINK4
Run Code Online (Sandbox Code Playgroud)
它是 bash 脚本的一部分。我正在寻找一种方法来制作一个关联数组,所以它看起来像
declare -A cols=( [SPRINGGREEN2]="0;47"...[DEEPPINK4]="0;53" )
Run Code Online (Sandbox Code Playgroud)
我可以很容易地手动完成。
但我想使用 for 循环来填充数组 cols=( [KEY]="vALUE" ) For 循环将把 47, 48, 49...53 取出到 VALUE 字段中,并将 SPRINGGREEN2...DEEPPINK4 放入关键字段。
我正在考虑使用 awk,但无法弄清楚如何隔离这两个字段并使用每个条目来填充数组。
我正在创建源和目标MAC地址的关联数组。
$ declare -a SrcDstMap
$ SrcDstMap["9c:4e:20:73:e2:72"]="ff:ff:ff:ff:ff:ff"
-bash: 9c: value too great for base (error token is "9c")
$ SrcDstMap["fc:4e:20:73:e2:72"]="ff:ff:ff:ff:ff:ff"
-bash: fc:4e:20:73:e2:72: syntax error in expression (error token is ":4e:20:73:e2:72")
Run Code Online (Sandbox Code Playgroud)
我怎么能告诉bash给定的键是一个完整的字符串。
我有两个对象.当我将这些作为键传递给关联数组并赋值时,所有值都存储错误(最后一个除外).
谁能告诉我我做错了什么?
var usrMrid = {name: "mrid"};
var usrXYZZ = {name: "xyzz"};
var comm = {};
comm[usrMrid] = "ONE";
comm[usrXYZZ] = "TWO";
console.log("usrMrid: " + comm[usrMrid]); // this gives TWO, when it should give ONE
console.log("usrXYZZ: " + comm[usrXYZZ]); // this works fineRun Code Online (Sandbox Code Playgroud)