btw. you could also try the code snippet below to show your foreach in line 23 is correct.
Maybe you should rethink how you handle the call-by-reference in the function-header and how you fill it up.
Regards
Gunny
Main Topics
Browse All Topicsthe listed code is giving me this error and i don't seem to see anything wrong with the line any help will be greatly appreciated
"Warning: Invalid argument supplied for foreach() in C:\wamp\www\filereading\st
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The testdata.txt file is populated using this program:
<?php
// Create some test data
$mydb[0]['name'] = "John";
$mydb[0]['city'] = "Boston";
$mydb[0]['age'] = "32";
$mydb[1]['name'] = "Max";
$mydb[1]['city'] = "London";
$mydb[1]['age'] = "41";
$mydb[2]['name'] = "Ann";
$mydb[2]['city'] = "Bonn";
$mydb[2]['age'] = "29";
$mydb[3]['name'] = "Peter";
$mydb[3]['city'] = "Dallas";
$mydb[3]['age'] = "28";
$mydb[4]['name'] = "Martin";
$mydb[4]['city'] = "Berlin";
$mydb[4]['age'] = "22";
function array2string($myarray,&$ou
foreach($myarray as $key=>$value){
if (is_array($value)) {
$parentkey .= $key."^";
array2string($value,$outpu
$parentkey = "";
}
else {
$output .= $parentkey.$key."^".$value
}
}
}
// Convert the array into string
array2string($mydb,$output
// Store the string in a file
$f1 = fopen("testdata.txt","w+")
fwrite($f1,$output);
fclose($f1);
?>
Business Accounts
Answer for Membership
by: gunnyPosted on 2009-04-29 at 15:02:17ID: 24265197
Hi Kiptieu,
I guess foreach is not your problem, the string2array function you implemented probably is ;-)
Just put a "print_r($newArray);" after calling string2array in order to check what your array data looks like.
Cheers
Gunny
Select allOpen in new window