需要关联数组

时间:2014-10-31 14:23:28

标签: php mysql arrays

我需要按照[id](oper - %%%%%%%%%%)在数组2中出现的顺序重新排列数组1,我不太确定如何接近这个。

阵列1

Array ( [0] => Array ( [id] => oper-4c597644-402490ee [amount] => 17498.5 ) [1] => Array ( [id] => oper-4f30019a-27f27473 [amount] => 10383.5 ) [2] => Array ( [id] => oper-4bceffd1-21e0af5b [amount] => 6277 ) [3] => Array ( [id] => oper-4f300d33-de9592e3 [amount] => 11382 ) [4] => Array ( [id] => oper-4c236420-0b11e945 [amount] => 14759 ) [5] => Array ( [id] => oper-50f6e4ad-9effbec7 [amount] => 3058 ) [6] => Array ( [id] => oper-4f05a90b-03b379f9 [amount] => 12112.5 ) [7] => Array ( [id] => oper-qtgjvw8y-1uqtw058 [amount] => 10023 ) [8] => Array ( [id] => oper-52657816-3d6516e2 [amount] => 3495 ) )

数组2

Array ( [0] => Array ( [0] => Bob [1] => oper-4bceffd1-21e0af5b ) [1] => Array ( [0] => Bob [1] => oper-4c236420-0b11e945 ) [2] => Array ( [0] => Bob [1] => oper-4c597644-402490ee ) [3] => Array ( [0] => Bob [1] => oper-4f05a90b-03b379f9 ) [4] => Array ( [0] => Bob [1] => oper-4f30019a-27f27473 ) [5] => Array ( [0] => Bob [1] => oper-4f300d33-de9592e3 ) [6] => Array ( [0] => Bob [1] => oper-50f6e4ad-9effbec7 ) [7] => Array ( [0] => Bob [1] => oper-52657816-3d6516e2 ) [8] => Array ( [0] => Bob [1] => oper-qtgjvw8y-1uqtw058 ) [9] => Array ( [0] => Empty [1] => ) [10] => Array ( [0] => Upg. [1] => ) [11] => Array ( [0] => Ren. [1] => ) )

鲍勃只是一个例子“名字” 到目前为止,这是我的代码(我知道这不是很干净,因为这不是用PDO完成的,我只是想让它在目前工作):

$result = mysql_query("SELECT * FROM tblOperatorGoals WHERE MonthlyGoal LIKE '$currentDate%'");

while ($row = mysql_fetch_array($result)) {
  $opernameArray[] = $row['OperatorName'];
  $operIDArray[] = $row['OperatorID'];
  $monthlyGoal[] = substr($row['MonthlyGoal'], 8);
  $operArray[] = array('name' => $row['OperatorName'], 'id' => $row['OperatorID']);
}

$result = mysql_query("SELECT * FROM tblUserPayments WHERE ChargeAmount IS NOT NULL AND  PaymentStatus='OK' AND PaymentDate LIKE '$currentDate%'");
while ($row = mysql_fetch_array($result)) {
  $operearnedArray[] = array(
      'amount' => $row['ChargeAmount'], 
      'id' => $row['OperatorID']);
}

foreach ($operearnedArray as $value) {
  if($value['id'] == '' || $value['id'] == null) {
    continue;
  }
  if(array_key_exists($value['id'], $operSums1)) {
    $operSums1[$value['id']] += $value['amount'];
  } else {
    $operSums1[$value['id']] = $value['amount'];
  }
}

foreach ($operSums1 as $id => $value) {
  if (in_array($id,$operIDArray)) {
    $operSums[] = array(
    'id' => $id,
    'amount' => $value);
  }
}

非常感谢任何帮助。联想阵列不是我的一杯茶。

基本上我正在寻找一个看起来像这样的数组:

Array ( [name] => Bob [id] => oper-%%%%%%%%%%%%%% [amount] => $$$$$$$$$$$ )...ect...ect...

0 个答案:

没有答案