|
Posted by Edward Vermillion on 10/21/35 11:28
I have two arrays:
$faqDataPost:
array
1 =>
array
'faq_order' => '1'
'faq_question' => 'What is the air speed of a fully laden swallow?'
'show_question' => '1'
'faq_answer' => 'African or European?'
3 =>
array
'faq_order' => '2'
'faq_question' => 'Where is our shrubbery?'
'show_question' => '1'
'faq_answer' => 'Nee! Nee!'
4 =>
array
'faq_order' => '3'
'faq_question' => 'Where is Lancelot?'
'show_question' => '1'
'faq_answer' => 'We eat and drink and dance a lot.'
$faqDataDB:
array
1 =>
array
'faq_data_id' => '1'
'faq_question' => 'What is the air speed of a fully laden swallow?'
'faq_answer' => 'African or European?'
'faq_order' => '1'
'show_question' => '0'
3 =>
array
'faq_data_id' => '3'
'faq_question' => 'Where is our shrubbery?'
'faq_answer' => 'Nee! Nee!'
'faq_order' => '2'
'show_question' => '0'
4 =>
array
'faq_data_id' => '4'
'faq_question' => 'Where is Lancelot?'
'faq_answer' => 'We eat and drink and dance a lot.'
'faq_order' => '3'
'show_question' => '0'
/************************************************************/
and this code(sorry the wrap is a bit off):
print'<br />$faqDataPost:<br />';var_dump($faqDataPost);
print'<br />$faqDataDB:<br />';var_dump($faqDataDB);
// Get the changed data...
//
foreach($faqDataPost as $key => $r) {
unset($faqDataDB[$key]['faq_data_id']);
$r['show_question'] = isset($r['show_question']) ? $r['show_question'] : 0;
print'<br />$r<br />';var_dump($r);
print'<br />DB<br />';var_dump($faqDataDB[$key]);
if((string)$r['show_question'] !==
(string)$faqDataDB[$key]['show_question']) {
print "<br />Does Not Match. Should show up in diff</br />";
}
$faqDataInsert[$key] = array_diff($r, $faqDataDB[$key]);
print'<br />diff<br/><pre>';print_r($faqDataInsert[$key]);print'</pre>';
}
/************************************************************/
and these results:
$r
array
'faq_order' => '1'
'faq_question' => 'What is the air speed of a fully laiden swallow?'
'show_question' => '1'
'faq_answer' => 'African or European?'
DB
array
'faq_question' => 'What is the air speed of a fully laiden swallow?'
'faq_answer' => 'African or European?'
'faq_order' => '1'
'show_question' => '0'
Does Not Match. Should show up in diff
diff
Array
(
)
$r
array
'faq_order' => '2'
'faq_question' => 'Where is our shrubbery?'
'show_question' => '1'
'faq_answer' => 'Nee! Nee!'
DB
array
'faq_question' => 'Where is our shrubbery?'
'faq_answer' => 'Nee! Nee!'
'faq_order' => '2'
'show_question' => '0'
Does Not Match. Should show up in diff
diff
Array
(
[show_question] => 1
)
$r
array
'faq_order' => '3'
'faq_question' => 'Where is Lancealot?'
'show_question' => '1'
'faq_answer' => 'We eat and drink and dance a lot.'
DB
array
'faq_question' => 'Where is Lancealot?'
'faq_answer' => 'We eat and drink and dance a lot.'
'faq_order' => '3'
'show_question' => '0'
Does Not Match. Should show up in diff
diff
Array
(
[show_question] => 1
)
/**************************************************************/
The problem is that in the first loop through the arrays, array_diff()
doesn't pick up that ['show_question'] is different, although it does
pick it up in the following loops.
The interesting bit is that arra_diff_assoc() DOES pick up the
difference in the first loop.
Both arrays are built in foreach() statements and I can't see any
difference between the first sub array and subsequent sub arrays that
would cause array_diff() to miss the diference in the first one.
If I change any of the other values in the first sub array, array_diff()
will pick those up fine, just not the ['show_question'] part.
I'm going to use array_diff_assoc(0 for this right now because it works
and that what matters, but does anyone know why I'm having this problem
with array_diff()? Can you see something that I'm missing?
Thanks!
Ed
Navigation:
[Reply to this message]
|