0

Hi,

I want to store the values that are in array($selected) into a single variable($result). How can i do it? Variable of $result should be 4,3,9. I get this error "Notice: Undefined variable: result in C:\wamp\www....".

Thanks

$selected=array("0" => 4, "1" => 3, "2" => 9 );
foreach ($selected as &$value) {
	$result="$result"."$value,";
}
echo $result;
3
Contributors
4
Replies
12
Views
8 Years
Discussion Span
Last Post by arifmufty
0

Solved.

for ($i=0;$i<sizeof($selected);$i++) {
	if($i!=0) {
		$strarray=$strarray.",".$selected[$i];
	} else {
		$strarray=$selected[$i];
	}
}
0

Sorry, I half read this post but is this what you're looking for?

// Creating the array.
$selected = array(4, 3, 9);

// Join the array elements into a string, seperated by commas.
$result = implode(",", $selected);

// Output the result.
echo $result;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.