Jump to content

[SOLVED] str_replace and array


Andrew R

Recommended Posts

I was wondering why the following script does not work. Basically I want to output each name in a separate text box, separates by a comma.

<? 
$users = array("".$user['user_name']."");
			  
$users = str_replace(" ", "", $users);

foreach($users as $key => $value) {

?>
<input type="text" value="<? echo $value; ?>" />
<? } ?>	

 

The format of user_name is, Andrew,Bob,James,Jim. 

 

Link to comment
https://forums.phpfreaks.com/topic/144767-solved-str_replace-and-array/
Share on other sites

example

<?php
$sep = "john,bob,redarrow";
$users = explode(',',$sep);
foreach($users as $value) {
?>
<input type="text" value="<? echo $value; ?>" />
<?php
}
?>

 

your way

<?php
$sep['users'] = "john,bob,redarrow";
$users = explode(',',$sep['users']);
foreach($users as $value) {
?>
<input type="text" value="<? echo $value; ?>" />
<?php
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.