php中二维数组的简单变量赋值

php中二维数组的简单变量赋值,php,arrays,Php,Arrays,我有一个二维数组,有两个键值,[program]和[balance],由WordPress中的MySQL SELECT语句创建。我知道[项目]的价值是什么(它们永远不会改变)-我感兴趣的是平衡 例如: *[program] = 'Sales', [balance] = 10,000* *[program] = 'Commission', [balance] = 1,250* 我要做的就是将平衡值分配给变量,因此我将有: *$sales = (the balance for the Sales

我有一个二维数组,有两个键值,[program]和[balance],由WordPress中的MySQL SELECT语句创建。我知道[项目]的价值是什么(它们永远不会改变)-我感兴趣的是平衡

例如:

*[program] = 'Sales', [balance] = 10,000*

*[program] = 'Commission', [balance] = 1,250*
我要做的就是将平衡值分配给变量,因此我将有:

*$sales = (the balance for the Sales program)*

*$commission = (the balance for the Commission program)*
我知道我在这里有点笨,但在搜索和使用php大约一个小时后,我看不出如何做到这一点。这是一个完全的大脑障碍,我能在网上找到的所有参考资料都在谈论循环,回应所有的价值观和东西


如果您能取消阻塞,我将不胜感激

你能分享实际的数组(或其中的一部分)吗?你能对你的答案提供一些评论,让so的未来访问者知道你在尝试什么吗?用逗号分隔参数$inputArray$program:$inputArray,$programUgh,我担心它需要一个完整的额外函数,而不是简单的函数。感谢您的回复-经过测试且有效。
//make a function
function findBalanceByProgram($inputArray,$program)
 //loop trough all the keys on the first dimension
 foreach($inputArray as $val){
    //check in the second dimension if your program is the same as the program you are checking for
    if($val['program']==$program) 
      //if so.. return the value and jump out of the function
      return $val['balance'];
  }
}

//an example of use.
echo findBalanceByProgram($yourArray,'sales');