array_walk - for what does this good?
Moderator: General Moderators
- pelegk2
- Forum Regular
- Posts: 633
- Joined: Thu Nov 27, 2003 5:02 am
- Location: Israel - the best place to live in after heaven
- Contact:
array_walk - for what does this good?
i read the array_walk help and didnt understand for what this is good?
does any 1 maybe have an idea?
does any 1 maybe have an idea?
- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
It is always a good idea to check the PHP Manual before posting questions. See how it's simple to find the reference for function array_walk: http://www.php.net/array_walk
Regards,
Scorphus.
Regards,
Scorphus.
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
I use it like so:
Say you've fetched all the data from a MySQL query into an array (mysql_fetch_array) and want to stripslashes all of the elements in one go? Just do:
But there are many other uses too.
Say you've fetched all the data from a MySQL query into an array (mysql_fetch_array) and want to stripslashes all of the elements in one go? Just do:
Code: Select all
function strip (&$item)
{
$item = stripslashes($item);
}
...
array_walk($data, 'strip');- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
No it doesn't. If you do not check for the magic quote settings and just addslashes regardless prior to inserting the info into the database then that is just poor coding. Effectively what you will have done is escaped the escapes, which is why you will have to then stripslashes from the data coming out of the database.launchcode wrote:Depends on your magic quote settings.
If you check and verify the data prior to inserting into the database and addslashes if nesseccary, then you will not have to stripslashes when retieving data from the database. If you have to stripslashes from the data being retrieved from the database then you are not storing the data correctly to begin with.
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
Yes, the thread is about the array_walk function, I am merley pointing out that there is something wrong if you have to stripslashes from data being retrieved from a database.launchcode wrote:there are many other uses for it array_walk which is what this thread is about, right?
Just because a stack of popular apps use it it doesn't make it right. I would class this approach as 'lazy coding' which when thinking about it probably makes it acceptable as PHP itself promotes lazy programming.launchcode wrote:I could name you a stack of very popular PHP applications that addslashes without a care for the world (or MQ GPC)
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
I'm sure this thread could go on for sometime and achieve nothing. Easy solution or correct solution, I'll leave the decision up to you. Suffice to say, either way, my initial comment on this matter still stands... 'There should be no need to stripslashes on data coming out of the database'. Of course, that statement is based on the fact that the data within the database is/was stored correctly to begin with.