从多维数组中提取值

时间:2017-08-09 02:14:51

标签: php arrays

/*
Blinks "BRENTON" in Morse Code, in pin # 12. 
 */

void setup() {
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}

int dot = 250;
int dash = dot * 3;
int space = dot * 7;
int rest = 250;

void A() {
  digitalWrite(12, HIGH);
  delay(dot);
  digitalWrite(12, LOW);
  delay(rest);
  digitalWrite(12, HIGH);
  delay(dash);
  digitalWrite(12, LOW);
  delay(space);
}
void B() {
  digitalWrite(12, HIGH);
  delay(dash);
  digitalWrite(12, LOW);
  delay(rest);
  digitalWrite(12, HIGH);
  delay(dot);
  digitalWrite(12, LOW);
  delay(rest);
  digitalWrite(12, HIGH);
  delay(dot);
  digitalWrite(12, LOW);
  delay(rest);
  digitalWrite(12, HIGH);
  delay(dot);
  digitalWrite(12, LOW);
  delay(space);
}
void R() {
  digitalWrite(12, HIGH);
  delay(dot);
  digitalWrite(12, LOW);
  delay(rest);
  digitalWrite(12, HIGH);
  delay(dash);
  digitalWrite(12, LOW);
  delay(rest);
  digitalWrite(12, HIGH);
  delay(dot);
  digitalWrite(12, LOW);
  delay(space);
}
void E() {
  digitalWrite(12, HIGH);
  delay(dot);
  digitalWrite(12, LOW);
  delay(space);
}
void N() {
  digitalWrite(12, HIGH);
  delay(dash);
  digitalWrite(12, LOW);
  delay(rest);
  digitalWrite(12, HIGH);
  delay(dot);
  digitalWrite(12, LOW);
  delay(space);
} 
void T() {
  digitalWrite(12, HIGH);
  delay(dash);
  digitalWrite(12, LOW);
  delay(space);
}
void O() {
  digitalWrite(12, HIGH);
  delay(dash);
  digitalWrite(12, LOW);
  delay(rest);
  digitalWrite(12, HIGH);
  delay(dash);
  digitalWrite(12, LOW);
  delay(rest);
  digitalWrite(12, HIGH);
  delay(dash);
  digitalWrite(12, LOW);
  delay(space);
}
void pin13(){
  digitalWrite(13, HIGH);
  delay(10000);
  digitalWrite(13, LOW);
  delay(1000);
}
void loopOne() {
  int i = 0;
  while(i < 100) {
    pin13();
    i++;
  }
}

void loop() {
  B();
  R();
  E();
  N();
  T();
  O();
  N();
}

从循环中填写。

下面是我填写的数组。我需要能够通过'雇主'和'评论'找到匹配并提取值,以便我可以重新更新此值。

$arrayDif = array();
$arrayDif[] = array('employer' => $employer,
                    'comment' => $comment,
                    'value' => $resultValue);

2 个答案:

答案 0 :(得分:2)

提取并重新更新值的一个命令,我建议使用foreach循环

&#13;
&#13;
Results = FILTER(CROSSJOIN(Data, Months), Data[Start Date] <= Months[Date] && Data[Finish Date] >= Months[Date])
&#13;
&#13;
&#13;

答案 1 :(得分:0)

不确定这是否是你要找的,但是你走了。我会使用一个函数和简单的循环。

&#13;
&#13;
<?php 
    $arrayDif = array();

    $arrayDif[] = array(
                    array('employer' => "Albury-Wodonga", 'comment' => "allOtherMembers", 'value' => "1 star"),
                    array('employer' => "Employer2", 'comment' => "Good Job", 'value' => "2 stars"),
                    array('employer' => "Employer3", 'comment' => "Smart", 'value' => "3 stars")
                );
    
    // Function for searching the array for the matches and returning the value of the match.
    function SearchMe($array, $searchEmployer, $searchComment){
        for($i = 0; $i < count($array); $i++){
            for($j = 0; $j < count($array[$i]); $j++){
                
                if(
                  $array[$i][$j]["employer"] == $searchEmployer &&
                  $array[$i][$j]["comment"] == $searchComment 
                  ){                    
                    return $array[$i][$j]["value"];
                }
            }   
        }
        return "No Match";
    }
    
    echo SearchMe($arrayDif, "Albury-Wodonga", "allOtherMembers");
?>
&#13;
&#13;
&#13;