Page 1 of 1

[SOLVED] Foreach statement

Posted: Thu Aug 02, 2007 12:42 am
by dream2rule

Code: Select all

<?php
$column_names = array("user_name" => "abcd","password" => "abc123#","email_id" => "abcd@yahoo.com","location" => "india");
$count = count($column_names);
echo $count."<br>";

foreach($column_names as $key => $value)
{
	echo "<br>"."$key => $value\n"."<br>";
	
}
?>
In the above code, i want to have a variable string that would contain all the keys together separated by a comma and another string containing all the values together separated by a comma.

i.e,

Code: Select all

$str_1 = "user_name, password, email_id, location";
and 
$str_2 = " abcd, abc123#, abcd@yahoo.com, india";
How should i proceed?

Thanks and Regards,
dream2rule

Posted: Thu Aug 02, 2007 12:49 am
by danf_1979
Maybe implode function is what you need.
http://cl2.php.net/implode

Posted: Thu Aug 02, 2007 3:18 am
by Gente

Posted: Thu Aug 02, 2007 5:11 am
by dream2rule
thanks all i have achieved the solution finally.