Adding values to an array from a textfiled

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
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Adding values to an array from a textfiled

Post by Calimero »

textfiled name='tf1'

I use GET to insert it into the process.php

This is a problem>

If someone enters three or more words into the textfield in this exact format: "word1 word2 word3 word4" - without the quotes off course :)

what is the code to create an array that will contain those (in this case) 4 words - in other words, I need a script to explode(this I know) a textfield and insert each value/word as a new member of an array (array1 or ex)

Already looked at the manual, lost several hours, everithing works but this part of inserting values into an array (or creating a new one with the values inserted) just won't work.

I'm not submitting the code, because its just a few lines of code, and is probably completely useless, some combination of built in functions in php, but nothing more.


Thanks Ahead !
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Post by litebearer »

I presume you mean something like this...

Code: Select all

<?PHP

$first_array = array ("item1", "item2", "item3");

$textfield = "word1 word2 word3 word4";
$second_array = explode(" ", $textfield);

$count = count($second_array);

echo $count;

$i = 0;

for ($i=0; $i < $count; $i ++) {
  $first_array[] = $second_array[$i];
}
$count2 = count($first_array);
$i = 0;
for ($i = 0; $i < $count2; $i ++) {
  echo $first_array[$i] . "<BR>";
}

?>
of course using the array_merge function is easier

http://us4.php.net/array_merge

Lite...


feyd | switch

Code: Select all

to

Code: Select all

tag.[/color]
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post by Calimero »

Any hints on how to use array_merge, I tried, didn't work

Thanks Ahead !
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

example only

Code: Select all

$newarray = array_merge($somearray, $anotherarray&#1111;, ...] );
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post by Calimero »

I know that syntax, but can it be used to create an array,

NOTE performance is very important here for me - it's a query for adwords and things like that

YIIIIIPEEEEEEEEEEEEEEEE my 100th POST :)))
now I'm good for another 100 :))))

Thanks Ahead !
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]array_merge[/php_man] creates a new array. That's all it does.
Post Reply