Re: [PHP] strings in a function return

2001-08-30 Thread


From: Gerard Samuel <[EMAIL PROTECTED]>
Date: Wed, Aug 29, 2001 at 09:58:12PM -0400
Message-ID: <[EMAIL PROTECTED]>
Subject: Re: [PHP] strings in a function return

> I found an error, but it didn't do me any good.
> I tried this, any tips...
> Thanks
> 
> function assign() {
> global $adminurl, $string;
> top();
> if ($string) {
> $data = explode ("|", $string);
> foreach ($data as $foo) {
>   echo $foo[0]; }
>   }
>   
> 
>   $array = array("$new_cat","$assigned_to","$job","$assigned_by");
>   $string = implode("|",$array);
>   return  $string;
> }
> 
> The variables that form $array are from the form





Why use array("$new_cat",...,"$assigned_by");
Loose the quotes: array ($new_cat,...,$assigned_by);

You don't need to use implode(). Just return the array. In the
calling function you can then get the results in two ways:

  $results = assign();  /* $results is an array */
or
  list ($new_cat,...,$assigned_by) = assign();

If you want a better answer on what is going wrong, you'll need to
send some more code. Eg the code that you've now replaced by .
It might just be that the error is in that part.



-- 

* R&zE:


-- 
-- Renze Munnik
-- DataLink BV
--
-- E: [EMAIL PROTECTED]
-- W: +31 23 5326162
-- F: +31 23 5322144
-- M: +31 6 21811143
--
-- Stationsplein 82
-- 2011 LM  HAARLEM
-- Netherlands
--
-- http://www.datalink.nl
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] strings in a function return

2001-08-29 Thread Gerard Samuel

Im beginning to think that functions aren't all that cracked up to be.
I may as well go back to my old "non function" way of coding.

I was displaying the form in the function because the application Im
using currently displays forms in functions.  Ill try and see what I can
do with this new found knowledge called 'functions'.

David Robley wrote:
 > On Thu, 30 Aug 2001 11:38, Gerard Samuel wrote:
 >
 >>top(); is a function that displays a menu, that works.
 >> is where the form goes.
 >>In its current setup less the array/implode/explode/foreach loop
 >>I can get it to echo 'a' return that I specify.  But its no good, when
 >>I have 7 seven fields in the form to process.
 >>
 >>David Robley wrote:
 >>
 >>>On Thu, 30 Aug 2001 10:45, Gerard Samuel wrote:
 >>>
 Mozilla sucks sometimes with email formatting.
 Correction==>
 
 Here is a snippet example.
 
 function assign() {
  global $adminurl, $string;
  top();
  if ($string) {
  $data = explode ("|", $string);
  echo "$data[0]";
  
}
  

 
    $array =  array("$new_cat,$assigned_to","$job","$assigned_by");
 
 >>>$string = implode("|",$array); return  $string;
 >>>
 >>>
 }
 
 The variables that form $array are from the form
 
 >>>Hrm - undefined function top()
 >>>
 >>>??  ??
 >>>
 >>>But the rest of it returns what I would expect - a comma followed by
 >>>two
 >>>
 >>>| - given that I don't have the values referenced in the array. And
 >>>| you
 >>>
 >>>won't either, as they aren't global and aren't passed as parameters.
 >>>
 >
 >
 > Why are you putting the form inside the function? There surely must be a
 > better way to achieve what you want (which is not clear from the 
snippet).
 > .
 >




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] strings in a function return

2001-08-29 Thread David Robley

On Thu, 30 Aug 2001 11:38, Gerard Samuel wrote:
> top(); is a function that displays a menu, that works.
>  is where the form goes.
> In its current setup less the array/implode/explode/foreach loop
> I can get it to echo 'a' return that I specify.  But its no good, when
> I have 7 seven fields in the form to process.
>
> David Robley wrote:
> > On Thu, 30 Aug 2001 10:45, Gerard Samuel wrote:
> >>Mozilla sucks sometimes with email formatting.
> >>Correction==>
> >>
> >>Here is a snippet example.
> >>
> >>function assign() {
> >>  global $adminurl, $string;
> >>  top();
> >>  if ($string) {
> >>  $data = explode ("|", $string);
> >>  echo "$data[0]";
> >>}
> >>
> >>
> >>$array =  array("$new_cat,$assigned_to","$job","$assigned_by");
> >
> > $string = implode("|",$array); return  $string;
> >
> >>}
> >>
> >>The variables that form $array are from the form
> >
> > Hrm - undefined function top()
> >
> > ??  ??
> >
> > But the rest of it returns what I would expect - a comma followed by
> > two
> >
> > | - given that I don't have the values referenced in the array. And
> > | you
> >
> > won't either, as they aren't global and aren't passed as parameters.


Why are you putting the form inside the function? There surely must be a 
better way to achieve what you want (which is not clear from the snippet).
.
-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   Oxymoron: Virtual Reality.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] strings in a function return

2001-08-29 Thread Gerard Samuel

top(); is a function that displays a menu, that works.
 is where the form goes.
In its current setup less the array/implode/explode/foreach loop
I can get it to echo 'a' return that I specify.  But its no good, when I 
have 7 seven fields in the form to process.


David Robley wrote:
> On Thu, 30 Aug 2001 10:45, Gerard Samuel wrote:
> 
>>Mozilla sucks sometimes with email formatting.
>>Correction==>
>>
>>Here is a snippet example.
>>
>>function assign() {
>>  global $adminurl, $string;
>>  top();
>>  if ($string) {
>>  $data = explode ("|", $string);
>>  echo "$data[0]";
>>  }
>>  
>>
>>  $array =  array("$new_cat,$assigned_to","$job","$assigned_by");
>>
>   $string = implode("|",$array); return  $string;
> 
>>}
>>
>>The variables that form $array are from the form
>>
> 
> Hrm - undefined function top()
> 
> ??  ??
> 
> But the rest of it returns what I would expect - a comma followed by two 
> | - given that I don't have the values referenced in the array. And you 
> won't either, as they aren't global and aren't passed as parameters.
> 
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] strings in a function return

2001-08-29 Thread David Robley

On Thu, 30 Aug 2001 10:45, Gerard Samuel wrote:
> Mozilla sucks sometimes with email formatting.
> Correction==>
>
> Here is a snippet example.
>
> function assign() {
>   global $adminurl, $string;
>   top();
>   if ($string) {
>   $data = explode ("|", $string);
>   echo "$data[0]";
>   }
>   
>
>   $array =  array("$new_cat,$assigned_to","$job","$assigned_by");
$string = implode("|",$array); return  $string;
> }
>
> The variables that form $array are from the form

Hrm - undefined function top()

??  ??

But the rest of it returns what I would expect - a comma followed by two 
| - given that I don't have the values referenced in the array. And you 
won't either, as they aren't global and aren't passed as parameters.

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   Shift happpens. - Doppler

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] strings in a function return

2001-08-29 Thread Gerard Samuel

I found an error, but it didn't do me any good.
I tried this, any tips...
Thanks

function assign() {
global $adminurl, $string;
top();
if ($string) {
$data = explode ("|", $string);
foreach ($data as $foo) {
echo $foo[0]; }
}


$array = array("$new_cat","$assigned_to","$job","$assigned_by");
$string = implode("|",$array);
  return  $string;
}

The variables that form $array are from the form





David Robley wrote:
   > On Thu, 30 Aug 2001 10:19, Gerard Samuel wrote:
   >
   >>I was doing it like so ==>
   >>$string = array(var1, var2...);
   >>return string;
   >>
   >>I also tried to implode the array into a string and return the result,
   >>but no go.
   >>
   >>David Robley wrote:
   >>
   >>>On Thu, 30 Aug 2001 09:35, Gerard Samuel wrote:
   >>>
   Hey all.  I just started venturing into functions.  I have a function
   that displays a form, but I have a problem with getting the multiple
   strings back after the submit.  Im tryed a return statement at the
   bottom of the function, but it cannot take more than one string.  I
   tried turning the array into a string and returning just the string
   made sure that the string name was in the global list, still no luck.
   Is it even possible to return mulitple values from a function??
   Thanks
   
   >>>You can only return one variable from a function, but that variable
   >>>can be an array.
   >>>
   >>>This is probably obvious, but you are assigning the result of the
   >>>function to a variable? Eg
   >>>
   >>>$result = my_function($my_parameter, $my_parameter);
   >>>
   >
   > Perhaps if you could show some of the code?
   >
   >






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] strings in a function return

2001-08-29 Thread Gerard Samuel

Mozilla sucks sometimes with email formatting.
Correction==>

Here is a snippet example.

function assign() {
  global $adminurl, $string;
  top();
  if ($string) {
  $data = explode ("|", $string);
  echo "$data[0]";
}


$array = array("$new_cat,$assigned_to","$job","$assigned_by"); 
 $string = implode("|",$array);
 return  $string;
}

The variables that form $array are from the form





David Robley wrote:
 > On Thu, 30 Aug 2001 10:19, Gerard Samuel wrote:
 >
 >>I was doing it like so ==>
 >>$string = array(var1, var2...);
 >>return string;
 >>
 >>I also tried to implode the array into a string and return the result,
 >>but no go.
 >>
 >>David Robley wrote:
 >>
 >>>On Thu, 30 Aug 2001 09:35, Gerard Samuel wrote:
 >>>
 Hey all.  I just started venturing into functions.  I have a function
 that displays a form, but I have a problem with getting the multiple
 strings back after the submit.  Im tryed a return statement at the
 bottom of the function, but it cannot take more than one string.  I
 tried turning the array into a string and returning just the string
 made sure that the string name was in the global list, still no luck.
 Is it even possible to return mulitple values from a function??
 Thanks
 
 >>>You can only return one variable from a function, but that variable
 >>>can be an array.
 >>>
 >>>This is probably obvious, but you are assigning the result of the
 >>>function to a variable? Eg
 >>>
 >>>$result = my_function($my_parameter, $my_parameter);
 >>>
 >
 > Perhaps if you could show some of the code?
 >
 >




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] strings in a function return

2001-08-29 Thread Gerard Samuel

Here is a snippet example.

function assign() {
 global $adminurl, $string;
 top();
 if ($string) {
 $data = explode ("|", $string);
 echo "$data[0]";
}


$array = array("$new_cat,$assigned_to","$job","$assigned_by")  
 $string = implode("|",$array);
 return  $string;
}

The variables that form $array are from the form





David Robley wrote:
> On Thu, 30 Aug 2001 10:19, Gerard Samuel wrote:
> 
>>I was doing it like so ==>
>>$string = array(var1, var2...);
>>return string;
>>
>>I also tried to implode the array into a string and return the result,
>>but no go.
>>
>>David Robley wrote:
>>
>>>On Thu, 30 Aug 2001 09:35, Gerard Samuel wrote:
>>>
Hey all.  I just started venturing into functions.  I have a function
that displays a form, but I have a problem with getting the multiple
strings back after the submit.  Im tryed a return statement at the
bottom of the function, but it cannot take more than one string.  I
tried turning the array into a string and returning just the string
made sure that the string name was in the global list, still no luck.
Is it even possible to return mulitple values from a function??
Thanks

>>>You can only return one variable from a function, but that variable
>>>can be an array.
>>>
>>>This is probably obvious, but you are assigning the result of the
>>>function to a variable? Eg
>>>
>>>$result = my_function($my_parameter, $my_parameter);
>>>
> 
> Perhaps if you could show some of the code?
> 
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] strings in a function return

2001-08-29 Thread David Robley

On Thu, 30 Aug 2001 10:19, Gerard Samuel wrote:
> I was doing it like so ==>
> $string = array(var1, var2...);
> return string;
>
> I also tried to implode the array into a string and return the result,
> but no go.
>
> David Robley wrote:
> > On Thu, 30 Aug 2001 09:35, Gerard Samuel wrote:
> >>Hey all.  I just started venturing into functions.  I have a function
> >>that displays a form, but I have a problem with getting the multiple
> >>strings back after the submit.  Im tryed a return statement at the
> >>bottom of the function, but it cannot take more than one string.  I
> >>tried turning the array into a string and returning just the string
> >>made sure that the string name was in the global list, still no luck.
> >>Is it even possible to return mulitple values from a function??
> >> Thanks
> >
> > You can only return one variable from a function, but that variable
> > can be an array.
> >
> > This is probably obvious, but you are assigning the result of the
> > function to a variable? Eg
> >
> > $result = my_function($my_parameter, $my_parameter);

Perhaps if you could show some of the code?

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   Oxymoron: Random Order.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] strings in a function return

2001-08-29 Thread Gerard Samuel

I was doing it like so ==>
$string = array(var1, var2...);
return string;

I also tried to implode the array into a string and return the result, 
but no go.


David Robley wrote:
> On Thu, 30 Aug 2001 09:35, Gerard Samuel wrote:
> 
>>Hey all.  I just started venturing into functions.  I have a function
>>that displays a form, but I have a problem with getting the multiple
>>strings back after the submit.  Im tryed a return statement at the
>>bottom of the function, but it cannot take more than one string.  I
>>tried turning the array into a string and returning just the string
>>made sure that the string name was in the global list, still no luck.
>>Is it even possible to return mulitple values from a function?? Thanks
>>
> 
> You can only return one variable from a function, but that variable can 
> be an array.
> 
> This is probably obvious, but you are assigning the result of the 
> function to a variable? Eg
> 
> $result = my_function($my_parameter, $my_parameter);
> 
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] strings in a function return

2001-08-29 Thread David Robley

On Thu, 30 Aug 2001 09:35, Gerard Samuel wrote:
> Hey all.  I just started venturing into functions.  I have a function
> that displays a form, but I have a problem with getting the multiple
> strings back after the submit.  Im tryed a return statement at the
> bottom of the function, but it cannot take more than one string.  I
> tried turning the array into a string and returning just the string
> made sure that the string name was in the global list, still no luck.
> Is it even possible to return mulitple values from a function?? Thanks

You can only return one variable from a function, but that variable can 
be an array.

This is probably obvious, but you are assigning the result of the 
function to a variable? Eg

$result = my_function($my_parameter, $my_parameter);

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   "I'm single," Tom said wanly.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]