Reply to Re: Passing array by reference.

Your name:

Reply:


Posted by Koncept on 01/15/07 21:17

In article <mtAqh.31090$k74.8961@text.news.blueyonder.co.uk>, David
Smithz <dave1900@blueyonder.co.uk> wrote:

> function check_if_FV_TES ($value, $key, &$ary_of_FVs) {
> echo "<BR>Here we are: $key $value," . substr($key, 0, 6);
>
> if (substr($key, 0, 6)=="FV_TES") {
> echo "<BR>We got a match:". substr($key,11);
> #Place this key and string into another variable (note we get the part
> after 9 characters as the first 9 identify fiel type, actual name starts
> then
> $ary_of_FVs[substr($key,11)] = $value;
> echo "<BR>:here is the array so far:";
> print_r($ary_of_FVs);
> };
> }
>
> #Create a blank array to stor the form variables
> $ary_Fulllist_of_FVs = array();
>
> #Call the array walk
> array_walk($_REQUEST, 'check_if_FV_INP', $ary_Fulllist_of_FVs );
>
>
> $ary_Fulllist_of_FVs - always had a blank array at the end.
>
> Any ideas?

You could also set $ary_of_FVs as *static* within the function body.

function check_if_FW_TES($value,$key)
{
*static* $ary_of_FVs= array();
// rest of your code
}


*Example*
--------

function counter()
{
static $count = 0;
return ++$count;
}

for ( $i = 0; $i < 10; ++$i )
{
echo counter(), "\n";
}

*Result*:
-------
1
2
3
4
5
6
7
8
9
10

--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация