I have a number of arrays, all of which could contain different headers.
I have built an array of all the headers so that I can use the if_array_key_exists function.
The code works fine for the first level of the array, but i just cant seem to figure out how to do it for the next layer. if the gender is not there it misses it out and thats the part i cant figure out
I have included 2 array examples and my code, i just havent included the code for building the header array.
Any help would be appreciated
the arrays (notice gender is in one and not the other, plus the interested array doesnt contain the same number of entries.
Expand|Select|Wrap|Line Numbers
- Array
- (
- [firstname] => example first
- [lastname] => example last
- [email] => example@example.com
- [gender] => Female
- [dob] => Array
- (
- [day] =>
- [month] =>
- [year] =>
- )
- [interested] => Array
- (
- [Haircare] => 1
- [Hair removal] => 1
- [Shaving] => 1
- [Grooming] => 1
- )
- [agree] => 1
- [x] => 104
- [y] => 17
- )
- <br><pre>Array
- (
- [firstname] => whiteyoh
- [lastname] => example
- [email] => another@hotmail.com.com
- [gender] => Male
- [dob] => Array
- (
- [day] => 16
- [month] => 3
- [year] => 1999
- )
- [interested] => Array
- (
- [Hair removal] => 1
- [Shaving] => 1
- )
- [agree] => 1
- [x] => 53
- [y] => 15
- )
THE CODE
Expand|Select|Wrap|Line Numbers
- foreach ($headers as $header){
- $reference .= $header . $tab;
- }
- $reference .= $cr;
- $SQL = "SELECT converted_text FROM forms_subscribed";
- $results = tep_db_query($SQL);
- while ($row = tep_db_fetch_array($results)){
- $entry = unserialize($row['converted_text']);
- foreach ($headers as $key=> $header){
- if (array_key_exists($header, $entry)){
- $reference .= $entry[$header] . $tab;
- } else {
- $reference .= " " . $tab;
- }
- $reference .= $cr;
- }