Can someone help me with array_walk/array_map?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Reply-Via-Newsgroup

    Can someone help me with array_walk/array_map?


    Folks,

    I have a multi-dimensional array that I read from my mysql database. I'd
    like to run strip slashes against each element and I'm pretty sure that
    array_walk() (or array_map) is likely to solve my problem - But I've not got
    the foggiest
    on how to use it - I've taken a look in the php.chm manual supplied from
    php.net and I don't seem to have had any success so far - Can anyone suggest
    how I could stripslashes to every element without having to build my own
    function?

    (I don't want to use my own function when one already exists in PHP - In
    part, because its more performance effective to use a precompiled function).

    all helps.. via the newsgroup... is much apprecaited,

    thanks
    randelld



  • Amir Khawaja

    #2
    Re: Can someone help me with array_walk/array_map?

    Reply-Via-Newsgroup wrote:
    [color=blue]
    > Folks,
    >
    > I have a multi-dimensional array that I read from my mysql database. I'd
    > like to run strip slashes against each element and I'm pretty sure that
    > array_walk() (or array_map) is likely to solve my problem - But I've not got
    > the foggiest
    > on how to use it - I've taken a look in the php.chm manual supplied from
    > php.net and I don't seem to have had any success so far - Can anyone suggest
    > how I could stripslashes to every element without having to build my own
    > function?
    >
    > (I don't want to use my own function when one already exists in PHP - In
    > part, because its more performance effective to use a precompiled function).
    >
    > all helps.. via the newsgroup... is much apprecaited,
    >
    > thanks
    > randelld
    >
    >
    >[/color]

    Try the following (untested) function:

    function stripSlashes(&$ var) {
    if (is_string($var )) {
    $var = stripslashes($v ar);
    } else { // assume it is an array
    foreach($var as $key => $value) {
    stripSlashes($v ar[$key]);
    }
    }
    }

    --
    Amir Khawaja.

    ----------------------------------
    Rules are written for those who lack the ability to truly reason, But
    for those who can, the rules become nothing more than guidelines, And
    live their lives governed not by rules but by reason.
    - James McGuigan

    Comment

    • Randell D.

      #3
      Re: Can someone help me with array_walk/array_map?


      "Amir Khawaja" <amir@gorebels. net> wrote in message
      news:VlwSb.1255 3$QJ3.1377@fed1 read04...[color=blue]
      > Reply-Via-Newsgroup wrote:
      >[color=green]
      > > Folks,
      > >
      > > I have a multi-dimensional array that I read from my mysql database.[/color][/color]
      I'd[color=blue][color=green]
      > > like to run strip slashes against each element and I'm pretty sure that
      > > array_walk() (or array_map) is likely to solve my problem - But I've not[/color][/color]
      got[color=blue][color=green]
      > > the foggiest
      > > on how to use it - I've taken a look in the php.chm manual supplied from
      > > php.net and I don't seem to have had any success so far - Can anyone[/color][/color]
      suggest[color=blue][color=green]
      > > how I could stripslashes to every element without having to build my own
      > > function?
      > >
      > > (I don't want to use my own function when one already exists in PHP - In
      > > part, because its more performance effective to use a precompiled[/color][/color]
      function).[color=blue][color=green]
      > >
      > > all helps.. via the newsgroup... is much apprecaited,
      > >
      > > thanks
      > > randelld
      > >
      > >
      > >[/color]
      >
      > Try the following (untested) function:
      >
      > function stripSlashes(&$ var) {
      > if (is_string($var )) {
      > $var = stripslashes($v ar);
      > } else { // assume it is an array
      > foreach($var as $key => $value) {
      > stripSlashes($v ar[$key]);
      > }
      > }
      > }
      >
      > --
      > Amir Khawaja.[/color]


      Thanks for that... But I have already come up with that as a solution but
      I'm sure there hsa got to be a more environmentally friendly method to go
      easy on the system to do what I need to do... I'm sure something like
      array_walk or array_map would do it in a single step...

      Cheers
      randelld


      Comment

      Working...