Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > PHP
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help.

Google
Closed Thread
 
LinkBack Thread Tools Display Modes
Old 07-01-2007, 3:38 PM   #1
Roger Smith
 
Roger Smith's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Trimming data in an Array

> function trim_data($formdata)
> {
> foreach ($formdata as $key => $value)
> {
> $key = trim($key);
> $value = trim($value);
> }
> return $formdata;
> }
>
> Can anyone spare the odd microsecond to point me in the right direction?


You're not doing anything with the trimmed values. Try something like:

function trim_data($formdata)
{
foreach ($formdata as $key => $value)
{
$newdata[trim($key)] = trim($value);
}
return $newdata;
}

-- Roger
Harry Nilsson's "The Point!" on DVD
http://www.harrynilsson.com/movie-5-1510.html


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Advertisements
Old 07-01-2007, 3:38 PM   #2
Graham Hall
 
Graham Hall's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Trimming data in an Array

Roger,

Many thanks - that works a treat.

I guess I must conclude that it is not possible to change the array elements
in a foreach loop? My old method looked logical in the same way that you
can say $apple = $apple + 1; or whatever.

Anyway, you've set me straight, and I'm most grateful.

Regards

Graham

"Roger Smith" <roger@ns_jadebox.com> wrote in message
news:RngRa.1409$d47.154616@twister.tampabay.rr.com ...
> > function trim_data($formdata)
> > {
> > foreach ($formdata as $key => $value)
> > {
> > $key = trim($key);
> > $value = trim($value);
> > }
> > return $formdata;
> > }
> >
> > Can anyone spare the odd microsecond to point me in the right direction?

>
> You're not doing anything with the trimmed values. Try something like:
>
> function trim_data($formdata)
> {
> foreach ($formdata as $key => $value)
> {
> $newdata[trim($key)] = trim($value);
> }
> return $newdata;
> }
>
> -- Roger
> Harry Nilsson's "The Point!" on DVD
> http://www.harrynilsson.com/movie-5-1510.html
>
>



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 3:38 PM   #3
Graham Hall
 
Graham Hall's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Trimming data in an Array

In this instance it was only the values that I wanted to change, but I
thought it best to make the function more general.

If you've got the time, I'd like to understand how you could in fact change
the values (I'm pretty new to this, so every bit of learning helps), but if
not don't worry - you've already solved my problem!

Many thanks again.

Regards

Graham

"Roger Smith" <roger@ns_jadebox.com> wrote in message
news:W3hRa.1478$d47.158367@twister.tampabay.rr.com ...
> > I guess I must conclude that it is not possible to change the array

> elements
> > in a foreach loop? My old method looked logical in the same way that

you
> > can say $apple = $apple + 1; or whatever.

>
> You could change the values, but changing the keys would be really messy.
> You'd have to add a new element and drop the old one inside the loop. I'm
> not sure how the "foreach" construction would react to that.
>
> -- Roger
>
>



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 3:39 PM   #4
Graham Hall
 
Graham Hall's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Trimming data in an Array

It looks a lot neater that way.

Thanks again, I've learned some very useful stuff from you.

Regards

G

"Roger Smith" <roger@ns_jadebox.com> wrote in message
news:TNlRa.119794$ic1.2358118@twister.tampabay.rr. com...
> > If you've got the time, I'd like to understand how you could in fact

> change
> > the values (I'm pretty new to this, so every bit of learning helps), but

> if
> > not don't worry - you've already solved my problem!

>
> You could put the following in the loop:
>
> $formdata[$key] = trim($value)
>
> -- Roger
> http://www.exclaimer.com/
> More than 16 Made-up Words
>
>



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 3:39 PM   #5
Graham Hall
 
Graham Hall's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Trimming data in an Array

Martin,

I didn't know that was how foreach worked. It makes sense now you've
pointed it out to me.

Thanks for getting involved in the thread.

Regards

Graham

"Martin C. Petersen" <mcp@phys.au.dk> wrote in message
news:3f15a57b$0$83045$edfadb0f@dtext01.news.tele.d k...
> > I guess I must conclude that it is not possible to change the array

> elements
> > in a foreach loop? My old method looked logical in the same way that

you
> > can say $apple = $apple + 1; or whatever.

> foreach ($array as $k => $v) puts a copy of the actual array-element into
> $v, so modifying $v does not effect the content of $array[$k].
>
>
> Martin
>
>



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Featured Websites
Free Space
Free Space
Free Space Free Space
Closed Thread
Tags: , ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting desperate - can't get data out of array with string index lawrence PHP 2 07-01-2007 3:18 PM
How do I sort This array? Karl McAuley PHP 1 07-01-2007 3:18 PM
How to delete an array key??? Barton PHP 0 07-01-2007 3:12 PM
Please help - Cracking elevation data format in data file Kevin Fishburne Software Programming 10 06-12-2007 11:31 PM


Featured Websites




All times are GMT +1. The time now is 12:05 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98