我需要重新排列陣列1中陣列2中[id](oper - %%%%%%%%%%)的顯示順序,而且我不太確定如何解決這個問題。關聯陣列
陣列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] =>))
鮑勃只是一個例子「名」 這是我到目前爲止的代碼(我知道這是不是乾淨,因爲這ISN」我只是試圖讓這個工作在這一刻):
$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);
}
}
任何幫助是極大的ppreciated。關聯數組只是不是我的一杯茶。
基本上我正在尋找,看起來像這樣的數組:
Array ([name] => Bob [id] => oper-%%%%%%%%%%%%%% [amount] => $$$$$$$$$$$)...ect...ect...
我已經編輯我的職務,我仍然無法使其正常工作。 – Juan 2014-10-31 14:25:20