Мне нужно переставить Array 1 по порядку, как [id] (oper – %%%%%%%%%%%%) появляется внутри массива 2, и я не совсем уверен, как подойти к этому.
Массив 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...