NYCPHP Meetup

NYPHP.org

[nycphp-talk] Second time array_walk failed for me

Daniel Kushner nyphp at websapp.com
Thu Nov 6 22:53:47 EST 2003


Can you paste the code that you're testing?

> -----Original Message-----
> From: talk-bounces at lists.nyphp.org
> [mailto:talk-bounces at lists.nyphp.org]On Behalf Of Phil Powell
> Sent: Thursday, November 06, 2003 10:46 PM
> To: NYPHP Talk
> Subject: Re: [nycphp-talk] Second time array_walk failed for me
>
>
> Ok, Daniel, let's investigate here:
>
> 1) what version of PHP are you using? I am using 4.1.3
>
> 2) Why does your work, here is mine and it does NOT work!
>
> <?php
>
>  function change(&$array, $index) {
>   $array =  strtoupper($array);
> }
>
> $blah = array('a', 'b', 'c');
> var_dump($blah);
> array_walk($blah, 'change');
> var_dump($blah);
>
> ?>
>
> Go to http://valsignalandet.com/aablah.php and see the results..
> It does NOT
> work!!!
>
> However, yours does (go to http://valsignalandet.com/aablah2.php) Here is
> the code I copied:
>
>  <?php
>  $arr = array('a', 'b', 'c');
>  var_dump($arr);
>  function change(&$array, $index) {
>  $array = 'I have changed you!';
>  }
>
>  array_walk($arr, 'change');
>  var_dump($arr);
>  ?>
>
>
> Why does yours work and mine does not, exact same logic only different
> methodology, one returns a result, the other does not..  That is
> not enough
> proof to just say "Good job PHP Team" and declare array_walk saves the
> universe from eternal peril.
>
> Phil
> ----- Original Message -----
> From: "Daniel Kushner" <nyphp at websapp.com>
> To: "NYPHP Talk" <talk at lists.nyphp.org>
> Sent: Thursday, November 06, 2003 10:18 PM
> Subject: RE: [nycphp-talk] Second time array_walk failed for me
>
>
> > Phil,
> >
> > >
> > > 1) Why does the PHP manual say that "array_walk" CAN change the values
> in
> > > the array, when, in fact, it can't?
> >
> > yes it can!
> >
> > > 2) If 1 is answerable, does that mean the manual is either
> misleading on
> > > array_walk, or, oh no WRONG?
> >
> > >From the manual:
> > Note: If function needs to be working with the actual values of
> the array,
> > specify the first parameter of function as a reference. Then,
> any changes
> > made to those elements will be made in the original array itself.
> >
> >
> > Some code to test:
> > <?php
> > $arr = array('a', 'b', 'c');
> > var_dump($arr);
> > function change(&$array, $index) {
> > $array = 'I have changed you!';
> > }
> >
> > array_walk($arr, 'change');
> > var_dump($arr);
> > ?>
> >
> > The output:
> > array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" }
> >
> > array(3) { [0]=> string(19) "I have changed you!" [1]=>
> string(19) "I have
> > changed you!" [2]=> string(19) "I have changed you!" }
> >
> >
> >
> > Oh my, it works !! Great job PHP Team !
> >
> > --Daniel
> >
> >
> > _______________________________________________
> > talk mailing list
> > talk at lists.nyphp.org
> > http://lists.nyphp.org/mailman/listinfo/talk
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk





More information about the talk mailing list