Have 2 php arrays.
One array is created from input values (array named $date_and_currency_array_for_comparision).
Array
(
[0] => Array
(
[CurrencyAbbreviation] => USD
[DateOfCurrencyRate] => 2013-07-22
)
[1] => Array
(
[CurrencyAbbreviation] => CAD
[DateOfCurrencyRate] => 2013-07-11
)
[3] => Array
(
[CurrencyAbbreviation] => CZK
[DateOfCurrencyRate] => 2013-07-31
)
)
Another array is created from values in mysql (named data_select_currency_rate)
Array
(
[0] => Array
(
[CurrencyAbbreviation] => CAD
[DateOfCurrencyRate] => 2013-07-11
)
[1] => Array
(
[CurrencyAbbreviation] => CZK
[DateOfCurrencyRate] => 2013-07-31
)
)
Need to create array with values from first array if these values does not exist in the second array.
At first tried
$currencies_that_must_insert_into_mysql = array_diff_assoc($date_and_currency_array_for_comparision, $data_select_currency_rate);
But get incorrect results. For example know that in mysql there is no [CurrencyAbbreviation] => USD but $currencies_that_must_insert_into_mysql shows [CurrencyAbbreviation] => CZK.
Then tried this
$data_difference = array();
foreach ($date_and_currency_array_for_comparision as $key_longer_array => $value_longer_array){
foreach ($data_select_currency_rate as $key_shorter_array => $value_shorter_array){
if (
($value_longer_array[CurrencyAbbreviation] != $value_shorter_array[CurrencyAbbreviation])
and ($value_longer_array[DateOfCurrencyRate] != $value_shorter_array[DateOfCurrencyRate]) ) {
$data_difference[$key_longer_array][CurrencyAbbreviation] = $value_longer_array[CurrencyAbbreviation];
$data_difference[$key_longer_array][DateOfCurrencyRate] = $value_longer_array[DateOfCurrencyRate];
}
}
}
But, if the second array is blank (no values in mysql), then print_r($data_difference) also shows nothing. And possibly there are other problems.
Please advice how to create array with values that exists in longer array and does not exists in shorter array
$value_longer_array[CurrencyAbbreviation]should be$value_longer_array['CurrencyAbbreviation']Undefined index. Actually it works not the same way as on website$date_and_currency_array_for_comparision = array ( array("CurrencyAbbreviation",'USD','CAD','CZK'), array("DateOfCurrencyRate",'2013-07-22','2013-07-11','2013-07-31'), );and$data_select_currency_rate = array ( array("CurrencyAbbreviation",'CAD','CZK'), array("DateOfCurrencyRate",'2013-07-11','2013-07-31'), );If i correctly understand what is necessary