![]() |
|
|
| Subject:
Compare to multi-dimensional arrays PHP
Category: Computers > Programming Asked by: drophit-ga List Price: $5.00 |
Posted:
09 Jul 2005 22:25 PDT
Expires: 08 Aug 2005 22:25 PDT Question ID: 541738 |
OK lets try that again: How could i compare these two arrays in order to create a new array: Array One -------------- Posted_Apps Array ( [0] => Array ( [lender_id] => 1 [app_count] => 2 ) [1] => Array ( [lender_id] => 3 [app_count] => 4 ) ) -------------- Array 2 ----------------- Eligible_LendersArray ( [0] => Array ( [lender_id] => 3 [daily_max] => 100 ) [1] => Array ( [lender_id] => 5 [daily_max] => 100 ) [2] => Array ( [lender_id] => 4 [daily_max] => 100 ) ) I want the comparison to be such that each instance of lender_id in array one is compared to the matching instance in the second array regarding the daily_max value and create a new array of eligible lender_ids for those that are equal or LESS than the daily max of array two. i.e. New_array ------------- ( [0] => 3 [1] => 5 [2] => 4 ) The new array should show all lenders who have daily_max LESS THAN or EQUAL TO app_count. Z |
|
| There is no answer at this time. |
|
| Subject:
Re: Compare to multi-dimensional arrays PHP
From: dedavai-ga on 21 Jul 2005 14:32 PDT |
This works to see if daily_max is less than or equal to app_count:
$new_arrray = NULL;
foreach ($Posted_Apps as $PA) {
foreach ($Eligible_Lenders as $EL) {
if($PA['lender_id'] == $EL['lender_id']
&& $EL['lender_id'] <= $PA['app_count']) {
$new_array[] = $EL['lender_id'];
}
}
}
----------
This works to see if app_count is less than or equal to daily_max:
$new_arrray = NULL;
foreach ($Posted_Apps as $PA) {
foreach ($Eligible_Lenders as $EL) {
if($PA['lender_id'] == $EL['lender_id']
&& $EL['lender_id'] > $PA['app_count']) {
$new_array[] = $EL['lender_id'];
}
}
} |
| Subject:
Re: Compare to multi-dimensional arrays PHP
From: dedavai-ga on 21 Jul 2005 14:34 PDT |
$new_array will contain the IDs of lenders who meet the requirement. |
| Subject:
Re: Compare to multi-dimensional arrays PHP
From: dedavai-ga on 21 Jul 2005 14:36 PDT |
DISREGARD THE FIRST COMMENT. I just noticed a bug. Here's the correct
code. $new_array will contain the IDs of eligible lenders.
--------------------------------------------------
Works if daily_max is less than or equal to app_count:
$new_arrray = NULL;
foreach ($Posted_Apps as $PA) {
foreach ($Eligible_Lenders as $EL) {
if($PA['lender_id'] == $EL['lender_id']
&& $EL['daily_max'] <= $PA['app_count']) {
$new_array[] = $EL['lender_id'];
}
}
}
--------------------------------------------------
Works if app_count is less than or equal to daily_max:
$new_arrray = NULL;
foreach ($Posted_Apps as $PA) {
foreach ($Eligible_Lenders as $EL) {
if($PA['lender_id'] == $EL['lender_id']
&& $EL['daily_max'] > $PA['app_count']) {
$new_array[] = $EL['lender_id'];
}
}
} |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |