dongluoheng3324 2014-06-22 04:53
浏览 75
已采纳

PHP:为一个值分配两个键; 使2个键具有同义定义

I am trying to create a way to systematically modify musical structures. A major scale is represented by numbers 1-7 (which represented in another way would be C=1, D=3, E=5, F=6, G=8, A=10, B=12, because all adjacent note pairs except EF and BC have an accidental between them.) In another array, a set of notes represented by unique ID numbers for each note that can be played on the instrument is each assigned a conceptual function from 1-7. Then, by comparing that set of notes to the list below, I can adjust the actual notes according to what scale is being played and show the player how to play the desired structure. For instance, the 7th note of a mixolydian scale is reduced by 1, and the fourth note of a lydian scale is increased by 1. (In the above example this would change B from 12 to 11, or would change F from 6 to 7.)

$qualityDefinitions = array(
"major" => array(), //default, no changes
"mixolydian" => array("7" => -1), //flat 7,etc 
"dorian" => array("3" => -1, "7" => -1),
"aeolian" => array("3" => -1, "6" => -1, "7" => -1),
"phyrgian" => array("2" => -1, "3" => -1, "6" => -1, "7" => -1),
"lydian" => array("4" => 1),
"locrian" => array("2" => -1, "3" => -1, "5" => -1, "6" => -1, "7" => -1)
);

However, I would like the ability to access the information stored in these array keys in a synonymous way. For instance, if I wish to build a dominant 7 chord (which has 1, 3, 5, b7), I need only take the modification of the mixolydian scale. But it is unusual to say the chord is "mixolydian"; it is more often described as "dominant 7", "dom7" or merely "7".

Is there any way to slightly change the data structure I am using for this need, so that I can access the same definition with: $qualityDefinitions['dom7'] and $qualityDefinitions['mixolydian'], or is it simply the case that I need to think about this in a conceptually different way and make substantial changes to my code? (Being a novice, I am aware that there is probably a more abstract and more effective way to do this that is slightly beyond my imagination right now, but if possible I would prefer to do it this way.)

  • 写回答

2条回答 默认 最新

  • dongmi1864 2014-06-22 05:03
    关注

    You can do this after:

    $qualityDefinitions["dominant 7"] = & $qualityDefinitions["mixolydian"];
    

    This makes the "dominant 7" key reference (or be a synonym of) the "mixolydian" key.

    If you want to easily have several of these made you can do so like this:

    $synonyms = array(
        "mixolydian" => array("dominant 7", "dom7", "7"),
        "lydian" => array("whatever", "it's", "called"),
    );
    
    foreach ($synonyms as $k => $a)
    {
        foreach ($a as $v)
            $qualityDefinitions[$v] = & $qualityDefinitions[$k];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改