Need help with arrays in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cool30
Forum Newbie
Posts: 12
Joined: Fri Jun 05, 2009 12:55 am

Need help with arrays in php

Post by cool30 »

I have a textbox -"textfield0" on a form. The user can enter as many phrases as he/she wants.The text in each line is a phrase.
There is another textbox-"textarea2" which should display each phrase which is entered in textfield0 to a new line in textarea2.(Each line should be copied as is)I am trying to use array here but the code isn't working. If someone can point out what am I doing wrong and how can I correct it.

Code: Select all

 
$phrase = array('textfield0');
foreach($phrase as $val)
{
  print"$val<BR>";
// this code doesn't work
}
 
 
 
Thanks
Last edited by Benjamin on Thu Jun 11, 2009 11:29 pm, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Need help with arrays in php

Post by Benjamin »

Code: Select all

$phrases = array_map('trim', explode("\n", $_POST['textfield0']));
cool30
Forum Newbie
Posts: 12
Joined: Fri Jun 05, 2009 12:55 am

Re: Need help with arrays in php

Post by cool30 »

Thanks
Post Reply