I'm trying to understand/debug a bit of PHP, the code is as follows:-
if (isset($data['date'])) { if (is_array($data['date'])) { foreach($data['date'] as $key => $date) { $date = $this->_convertDate(trim($date)); if (!$date) unset($data['date'][$key]); else $data['date'][$key] = $date; dbglog($data, "Converted data"); } } else { unset($data['date']); } }
What's happening is that it always ends up with nothing in $data (what's reported by that dbglog()).
I'm confused by what happens with that foreach as, as far as I can see, $data['date'] is just what I would call a list in python, it's not an array indexed by values it's just a sequential array.
So, in the foreach loop $key gets the values from the $date array and $date is empty (confirmed by further dbglog()).
Am I understanding this right? If I create an array:-
$aa = array('abc', 'def', 'ghi', 'jkl');
Then do:-
foreach $aa as $x => $y { // what do I get for $x and $y here? }
Sorry this is a bit confused/muddled, I'm definitely not a PHP programmer.