Re: [PHP] function array problem

2009-02-18 Thread Thodoris



I've had a bit of a problem with a function I'm using for a form.
Essentially, the function looks like this:

function addEvent($values = Array('name' = '', 'venue' = '',
'description' = '', 'errors' = Array()))
{
// code here displays the form
}

The function is used to both display an empty form, and the form
populated with values again should there be any validation errors.

Now this works fine when the form has been filled out and there are
errors present, as I can call the function with the correct array
values. However, when I call the function with no arguments (intending
the function to populate the $values array itself) all it does is
present me with an empty array. A print_r($values) just returns
Array( ), no key values defined.

I altered the function to this:

function addEvent($values = Array())
{
if(count($values) == 0)
{
$values = Array('name' = '', 'venue' = '', 'description' =
'', 'errors' = Array());
}
// code here displays the form
}

then all works as intended. Question is, am I being dense, or is there a
reason why this shouldn't work?


Ash
www.ashleysheridan.co.uk


  


While reading this thread I've noticed that you all use venue in the 
index of the parameter array. Is this intended or you actually mean value?


You may want to consider these functions:

|func_get_args
||func_get_arg|
|func_num_args|

to make the functions input more loose and have it accept multiple 
formats as needed like one dimensional, two dimensional or simple 
parameters the same time.


--
Thodoris



Re: [PHP] function array problem

2009-02-18 Thread Shawn McKenzie
Thodoris wrote:
 
 I've had a bit of a problem with a function I'm using for a form.
 Essentially, the function looks like this:

 function addEvent($values = Array('name' = '', 'venue' = '',
 'description' = '', 'errors' = Array()))
 {
 // code here displays the form
 }

 The function is used to both display an empty form, and the form
 populated with values again should there be any validation errors.

 Now this works fine when the form has been filled out and there are
 errors present, as I can call the function with the correct array
 values. However, when I call the function with no arguments (intending
 the function to populate the $values array itself) all it does is
 present me with an empty array. A print_r($values) just returns
 Array( ), no key values defined.

 I altered the function to this:

 function addEvent($values = Array())
 {
 if(count($values) == 0)
 {
 $values = Array('name' = '', 'venue' = '', 'description' =
 '', 'errors' = Array());
 }
 // code here displays the form
 }

 then all works as intended. Question is, am I being dense, or is there a
 reason why this shouldn't work?


 Ash
 www.ashleysheridan.co.uk


   
 
 While reading this thread I've noticed that you all use venue in the
 index of the parameter array. Is this intended or you actually mean
 value?
 
 You may want to consider these functions:
 
 |func_get_args
 ||func_get_arg|
 |func_num_args|
 
 to make the functions input more loose and have it accept multiple
 formats as needed like one dimensional, two dimensional or simple
 parameters the same time.
 
I'm not sure what the OP meant, but venue is a location, for example the
location of a Metallica concert or the location of a court proceeding.

Latin venire (to come)

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function array problem

2009-02-18 Thread Ashley Sheridan
On Wed, 2009-02-18 at 10:21 -0600, Shawn McKenzie wrote:
 Thodoris wrote:
  
  I've had a bit of a problem with a function I'm using for a form.
  Essentially, the function looks like this:
 
  function addEvent($values = Array('name' = '', 'venue' = '',
  'description' = '', 'errors' = Array()))
  {
  // code here displays the form
  }
 
  The function is used to both display an empty form, and the form
  populated with values again should there be any validation errors.
 
  Now this works fine when the form has been filled out and there are
  errors present, as I can call the function with the correct array
  values. However, when I call the function with no arguments (intending
  the function to populate the $values array itself) all it does is
  present me with an empty array. A print_r($values) just returns
  Array( ), no key values defined.
 
  I altered the function to this:
 
  function addEvent($values = Array())
  {
  if(count($values) == 0)
  {
  $values = Array('name' = '', 'venue' = '', 'description' =
  '', 'errors' = Array());
  }
  // code here displays the form
  }
 
  then all works as intended. Question is, am I being dense, or is there a
  reason why this shouldn't work?
 
 
  Ash
  www.ashleysheridan.co.uk
 
 

  
  While reading this thread I've noticed that you all use venue in the
  index of the parameter array. Is this intended or you actually mean
  value?
  
  You may want to consider these functions:
  
  |func_get_args
  ||func_get_arg|
  |func_num_args|
  
  to make the functions input more loose and have it accept multiple
  formats as needed like one dimensional, two dimensional or simple
  parameters the same time.
  
 I'm not sure what the OP meant, but venue is a location, for example the
 location of a Metallica concert or the location of a court proceeding.
 
 Latin venire (to come)
 
 -- 
 Thanks!
 -Shawn
 http://www.spidean.com
 
Yes it was intended, as the queries all relate to an event-based CMS I'm
putting together.



Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] function array problem

2009-02-17 Thread Ashley Sheridan
I've had a bit of a problem with a function I'm using for a form.
Essentially, the function looks like this:

function addEvent($values = Array('name' = '', 'venue' = '',
'description' = '', 'errors' = Array()))
{
// code here displays the form
}

The function is used to both display an empty form, and the form
populated with values again should there be any validation errors.

Now this works fine when the form has been filled out and there are
errors present, as I can call the function with the correct array
values. However, when I call the function with no arguments (intending
the function to populate the $values array itself) all it does is
present me with an empty array. A print_r($values) just returns
Array( ), no key values defined.

I altered the function to this:

function addEvent($values = Array())
{
if(count($values) == 0)
{
$values = Array('name' = '', 'venue' = '', 'description' =
'', 'errors' = Array());
}
// code here displays the form
}

then all works as intended. Question is, am I being dense, or is there a
reason why this shouldn't work?


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function array problem

2009-02-17 Thread Bastien Koert
On Tue, Feb 17, 2009 at 3:10 PM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

 I've had a bit of a problem with a function I'm using for a form.
 Essentially, the function looks like this:

 function addEvent($values = Array('name' = '', 'venue' = '',
 'description' = '', 'errors' = Array()))
 {
// code here displays the form
 }

 The function is used to both display an empty form, and the form
 populated with values again should there be any validation errors.

 Now this works fine when the form has been filled out and there are
 errors present, as I can call the function with the correct array
 values. However, when I call the function with no arguments (intending
 the function to populate the $values array itself) all it does is
 present me with an empty array. A print_r($values) just returns
 Array( ), no key values defined.

 I altered the function to this:

 function addEvent($values = Array())
 {
if(count($values) == 0)
{
$values = Array('name' = '', 'venue' = '', 'description' =
 '', 'errors' = Array());
}
// code here displays the form
 }

 then all works as intended. Question is, am I being dense, or is there a
 reason why this shouldn't work?


 Ash
 www.ashleysheridan.co.uk


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



i tend to do

function addEvent($values='')
{
  if (!is_array($values))
 {
   $values = Array('name' = '', 'venue' = '', 'description' ='',
'errors' = Array());
 }
  //rest of the code

}



-- 

Bastien

Cat, the other other white meat


Re: [PHP] function array problem

2009-02-17 Thread Ashley Sheridan
On Tue, 2009-02-17 at 15:13 -0500, Bastien Koert wrote:
 On Tue, Feb 17, 2009 at 3:10 PM, Ashley Sheridan
 a...@ashleysheridan.co.ukwrote:
 
  I've had a bit of a problem with a function I'm using for a form.
  Essentially, the function looks like this:
 
  function addEvent($values = Array('name' = '', 'venue' = '',
  'description' = '', 'errors' = Array()))
  {
 // code here displays the form
  }
 
  The function is used to both display an empty form, and the form
  populated with values again should there be any validation errors.
 
  Now this works fine when the form has been filled out and there are
  errors present, as I can call the function with the correct array
  values. However, when I call the function with no arguments (intending
  the function to populate the $values array itself) all it does is
  present me with an empty array. A print_r($values) just returns
  Array( ), no key values defined.
 
  I altered the function to this:
 
  function addEvent($values = Array())
  {
 if(count($values) == 0)
 {
 $values = Array('name' = '', 'venue' = '', 'description' =
  '', 'errors' = Array());
 }
 // code here displays the form
  }
 
  then all works as intended. Question is, am I being dense, or is there a
  reason why this shouldn't work?
 
 
  Ash
  www.ashleysheridan.co.uk
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 i tend to do
 
 function addEvent($values='')
 {
   if (!is_array($values))
  {
$values = Array('name' = '', 'venue' = '', 'description' ='',
 'errors' = Array());
  }
   //rest of the code
 
 }
 
 
 
It's a shame really, because to me it just seems darn messy to have to
perform a check inside the function itself and initialise variables
there. Putting such initialisations inside the parentheses seems more
elegant. :(


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function array problem

2009-02-17 Thread Andrew Ballard
On Tue, Feb 17, 2009 at 3:10 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 I've had a bit of a problem with a function I'm using for a form.
 Essentially, the function looks like this:

 function addEvent($values = Array('name' = '', 'venue' = '',
 'description' = '', 'errors' = Array()))
 {
// code here displays the form
 }

 The function is used to both display an empty form, and the form
 populated with values again should there be any validation errors.

 Now this works fine when the form has been filled out and there are
 errors present, as I can call the function with the correct array
 values. However, when I call the function with no arguments (intending
 the function to populate the $values array itself) all it does is
 present me with an empty array. A print_r($values) just returns
 Array( ), no key values defined.

 I altered the function to this:

 function addEvent($values = Array())
 {
if(count($values) == 0)
{
$values = Array('name' = '', 'venue' = '', 'description' =
 '', 'errors' = Array());
}
// code here displays the form
 }

 then all works as intended. Question is, am I being dense, or is there a
 reason why this shouldn't work?


 Ash
 www.ashleysheridan.co.uk



It seems to work OK for me. I typically use your altered format or the
form that Bastien posted (except I usually default the parameters to
null rather than an empty string) though.

?php

function addEvent($values = Array('name' = '', 'venue' = '',
'description' = '', 'errors' = Array()))
{
   // code here displays the form
   print_r($values);
}

addEvent();

?


X-Powered-By: PHP/5.2.0
Content-type: text/html

Array
(
[name] =
[venue] =
[description] =
[errors] = Array
(
)

)


Andrew

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function array problem

2009-02-17 Thread Andrew Ballard
On Tue, Feb 17, 2009 at 3:29 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 On Tue, 2009-02-17 at 15:13 -0500, Bastien Koert wrote:
 On Tue, Feb 17, 2009 at 3:10 PM, Ashley Sheridan
 a...@ashleysheridan.co.ukwrote:

  I've had a bit of a problem with a function I'm using for a form.
  Essentially, the function looks like this:
 
  function addEvent($values = Array('name' = '', 'venue' = '',
  'description' = '', 'errors' = Array()))
  {
 // code here displays the form
  }
 
  The function is used to both display an empty form, and the form
  populated with values again should there be any validation errors.
 
  Now this works fine when the form has been filled out and there are
  errors present, as I can call the function with the correct array
  values. However, when I call the function with no arguments (intending
  the function to populate the $values array itself) all it does is
  present me with an empty array. A print_r($values) just returns
  Array( ), no key values defined.
 
  I altered the function to this:
 
  function addEvent($values = Array())
  {
 if(count($values) == 0)
 {
 $values = Array('name' = '', 'venue' = '', 'description' =
  '', 'errors' = Array());
 }
 // code here displays the form
  }
 
  then all works as intended. Question is, am I being dense, or is there a
  reason why this shouldn't work?
 
 
  Ash
  www.ashleysheridan.co.uk
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 

 i tend to do

 function addEvent($values='')
 {
   if (!is_array($values))
  {
$values = Array('name' = '', 'venue' = '', 'description' ='',
 'errors' = Array());
  }
   //rest of the code

 }



 It's a shame really, because to me it just seems darn messy to have to
 perform a check inside the function itself and initialise variables
 there. Putting such initialisations inside the parentheses seems more
 elegant. :(


 Ash
 www.ashleysheridan.co.uk

To each their own. I think having an array (especially nested arrays)
embedded in the parameter list of a function declaration like that
looks kind of ugly, but that's just me.

Andrew

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function array problem

2009-02-17 Thread Ashley Sheridan
On Tue, 2009-02-17 at 15:19 -0500, Andrew Ballard wrote:
 On Tue, Feb 17, 2009 at 3:10 PM, Ashley Sheridan
 a...@ashleysheridan.co.uk wrote:
  I've had a bit of a problem with a function I'm using for a form.
  Essentially, the function looks like this:
 
  function addEvent($values = Array('name' = '', 'venue' = '',
  'description' = '', 'errors' = Array()))
  {
 // code here displays the form
  }
 
  The function is used to both display an empty form, and the form
  populated with values again should there be any validation errors.
 
  Now this works fine when the form has been filled out and there are
  errors present, as I can call the function with the correct array
  values. However, when I call the function with no arguments (intending
  the function to populate the $values array itself) all it does is
  present me with an empty array. A print_r($values) just returns
  Array( ), no key values defined.
 
  I altered the function to this:
 
  function addEvent($values = Array())
  {
 if(count($values) == 0)
 {
 $values = Array('name' = '', 'venue' = '', 'description' =
  '', 'errors' = Array());
 }
 // code here displays the form
  }
 
  then all works as intended. Question is, am I being dense, or is there a
  reason why this shouldn't work?
 
 
  Ash
  www.ashleysheridan.co.uk
 
 
 
 It seems to work OK for me. I typically use your altered format or the
 form that Bastien posted (except I usually default the parameters to
 null rather than an empty string) though.
 
 ?php
 
 function addEvent($values = Array('name' = '', 'venue' = '',
 'description' = '', 'errors' = Array()))
 {
// code here displays the form
print_r($values);
 }
 
 addEvent();
 
 ?
 
 
 X-Powered-By: PHP/5.2.0
 Content-type: text/html
 
 Array
 (
 [name] =
 [venue] =
 [description] =
 [errors] = Array
 (
 )
 
 )
 
 
 Andrew
That's quite odd then! I might have to try it on another server, could
be my main one is having a hissy fit?!


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function array problem

2009-02-17 Thread Ashley Sheridan
On Tue, 2009-02-17 at 15:21 -0500, Andrew Ballard wrote:
 On Tue, Feb 17, 2009 at 3:29 PM, Ashley Sheridan
 a...@ashleysheridan.co.uk wrote:
  On Tue, 2009-02-17 at 15:13 -0500, Bastien Koert wrote:
  On Tue, Feb 17, 2009 at 3:10 PM, Ashley Sheridan
  a...@ashleysheridan.co.ukwrote:
 
   I've had a bit of a problem with a function I'm using for a form.
   Essentially, the function looks like this:
  
   function addEvent($values = Array('name' = '', 'venue' = '',
   'description' = '', 'errors' = Array()))
   {
  // code here displays the form
   }
  
   The function is used to both display an empty form, and the form
   populated with values again should there be any validation errors.
  
   Now this works fine when the form has been filled out and there are
   errors present, as I can call the function with the correct array
   values. However, when I call the function with no arguments (intending
   the function to populate the $values array itself) all it does is
   present me with an empty array. A print_r($values) just returns
   Array( ), no key values defined.
  
   I altered the function to this:
  
   function addEvent($values = Array())
   {
  if(count($values) == 0)
  {
  $values = Array('name' = '', 'venue' = '', 'description' =
   '', 'errors' = Array());
  }
  // code here displays the form
   }
  
   then all works as intended. Question is, am I being dense, or is there a
   reason why this shouldn't work?
  
  
   Ash
   www.ashleysheridan.co.uk
  
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
  
 
  i tend to do
 
  function addEvent($values='')
  {
if (!is_array($values))
   {
 $values = Array('name' = '', 'venue' = '', 'description' ='',
  'errors' = Array());
   }
//rest of the code
 
  }
 
 
 
  It's a shame really, because to me it just seems darn messy to have to
  perform a check inside the function itself and initialise variables
  there. Putting such initialisations inside the parentheses seems more
  elegant. :(
 
 
  Ash
  www.ashleysheridan.co.uk
 
 To each their own. I think having an array (especially nested arrays)
 embedded in the parameter list of a function declaration like that
 looks kind of ugly, but that's just me.
 
 Andrew
 
You kidding? Nested arrays is what makes me get up in the morning!


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function array problem

2009-02-17 Thread Lewis Wright
What about:


function addEvent($values='')
{
!is_array($values)  $values = Array('name' = '', 'venue' = '',
'description' ='',
'errors' = Array());

 //rest of the code

}

It's nice and sort.

2009/2/17 Ashley Sheridan a...@ashleysheridan.co.uk:
 On Tue, 2009-02-17 at 15:21 -0500, Andrew Ballard wrote:
 On Tue, Feb 17, 2009 at 3:29 PM, Ashley Sheridan
 a...@ashleysheridan.co.uk wrote:
  On Tue, 2009-02-17 at 15:13 -0500, Bastien Koert wrote:
  On Tue, Feb 17, 2009 at 3:10 PM, Ashley Sheridan
  a...@ashleysheridan.co.ukwrote:
 
   I've had a bit of a problem with a function I'm using for a form.
   Essentially, the function looks like this:
  
   function addEvent($values = Array('name' = '', 'venue' = '',
   'description' = '', 'errors' = Array()))
   {
  // code here displays the form
   }
  
   The function is used to both display an empty form, and the form
   populated with values again should there be any validation errors.
  
   Now this works fine when the form has been filled out and there are
   errors present, as I can call the function with the correct array
   values. However, when I call the function with no arguments (intending
   the function to populate the $values array itself) all it does is
   present me with an empty array. A print_r($values) just returns
   Array( ), no key values defined.
  
   I altered the function to this:
  
   function addEvent($values = Array())
   {
  if(count($values) == 0)
  {
  $values = Array('name' = '', 'venue' = '', 'description' =
   '', 'errors' = Array());
  }
  // code here displays the form
   }
  
   then all works as intended. Question is, am I being dense, or is there a
   reason why this shouldn't work?
  
  
   Ash
   www.ashleysheridan.co.uk
  
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
  
 
  i tend to do
 
  function addEvent($values='')
  {
if (!is_array($values))
   {
 $values = Array('name' = '', 'venue' = '', 'description' ='',
  'errors' = Array());
   }
//rest of the code
 
  }
 
 
 
  It's a shame really, because to me it just seems darn messy to have to
  perform a check inside the function itself and initialise variables
  there. Putting such initialisations inside the parentheses seems more
  elegant. :(
 
 
  Ash
  www.ashleysheridan.co.uk

 To each their own. I think having an array (especially nested arrays)
 embedded in the parameter list of a function declaration like that
 looks kind of ugly, but that's just me.

 Andrew

 You kidding? Nested arrays is what makes me get up in the morning!


 Ash
 www.ashleysheridan.co.uk


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function array problem

2009-02-17 Thread Ashley Sheridan
On Tue, 2009-02-17 at 20:35 +, Lewis Wright wrote:
 What about:
 
 
 function addEvent($values='')
 {
 !is_array($values)  $values = Array('name' = '', 'venue' = '',
 'description' ='',
 'errors' = Array());
 
  //rest of the code
 
 }
 
 It's nice and sort.
 
 2009/2/17 Ashley Sheridan a...@ashleysheridan.co.uk:
  On Tue, 2009-02-17 at 15:21 -0500, Andrew Ballard wrote:
  On Tue, Feb 17, 2009 at 3:29 PM, Ashley Sheridan
  a...@ashleysheridan.co.uk wrote:
   On Tue, 2009-02-17 at 15:13 -0500, Bastien Koert wrote:
   On Tue, Feb 17, 2009 at 3:10 PM, Ashley Sheridan
   a...@ashleysheridan.co.ukwrote:
  
I've had a bit of a problem with a function I'm using for a form.
Essentially, the function looks like this:
   
function addEvent($values = Array('name' = '', 'venue' = '',
'description' = '', 'errors' = Array()))
{
   // code here displays the form
}
   
The function is used to both display an empty form, and the form
populated with values again should there be any validation errors.
   
Now this works fine when the form has been filled out and there are
errors present, as I can call the function with the correct array
values. However, when I call the function with no arguments (intending
the function to populate the $values array itself) all it does is
present me with an empty array. A print_r($values) just returns
Array( ), no key values defined.
   
I altered the function to this:
   
function addEvent($values = Array())
{
   if(count($values) == 0)
   {
   $values = Array('name' = '', 'venue' = '', 'description' =
'', 'errors' = Array());
   }
   // code here displays the form
}
   
then all works as intended. Question is, am I being dense, or is 
there a
reason why this shouldn't work?
   
   
Ash
www.ashleysheridan.co.uk
   
   
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
   
   
  
   i tend to do
  
   function addEvent($values='')
   {
 if (!is_array($values))
{
  $values = Array('name' = '', 'venue' = '', 'description' ='',
   'errors' = Array());
}
 //rest of the code
  
   }
  
  
  
   It's a shame really, because to me it just seems darn messy to have to
   perform a check inside the function itself and initialise variables
   there. Putting such initialisations inside the parentheses seems more
   elegant. :(
  
  
   Ash
   www.ashleysheridan.co.uk
 
  To each their own. I think having an array (especially nested arrays)
  embedded in the parameter list of a function declaration like that
  looks kind of ugly, but that's just me.
 
  Andrew
 
  You kidding? Nested arrays is what makes me get up in the morning!
 
 
  Ash
  www.ashleysheridan.co.uk
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
That would make it look a little bit neater than what I already have,
might go with that.


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function array problem

2009-02-17 Thread Shawn McKenzie
Andrew Ballard wrote:
 On Tue, Feb 17, 2009 at 3:10 PM, Ashley Sheridan
 a...@ashleysheridan.co.uk wrote:
 I've had a bit of a problem with a function I'm using for a form.
 Essentially, the function looks like this:

 function addEvent($values = Array('name' = '', 'venue' = '',
 'description' = '', 'errors' = Array()))
 {
// code here displays the form
 }

 The function is used to both display an empty form, and the form
 populated with values again should there be any validation errors.

 Now this works fine when the form has been filled out and there are
 errors present, as I can call the function with the correct array
 values. However, when I call the function with no arguments (intending
 the function to populate the $values array itself) all it does is
 present me with an empty array. A print_r($values) just returns
 Array( ), no key values defined.

 I altered the function to this:

 function addEvent($values = Array())
 {
if(count($values) == 0)
{
$values = Array('name' = '', 'venue' = '', 'description' =
 '', 'errors' = Array());
}
// code here displays the form
 }

 then all works as intended. Question is, am I being dense, or is there a
 reason why this shouldn't work?


 Ash
 www.ashleysheridan.co.uk


 
 It seems to work OK for me. I typically use your altered format or the
 form that Bastien posted (except I usually default the parameters to
 null rather than an empty string) though.
 
 ?php
 
 function addEvent($values = Array('name' = '', 'venue' = '',
 'description' = '', 'errors' = Array()))
 {
// code here displays the form
print_r($values);
 }
 
 addEvent();
 
 ?
 
 
 X-Powered-By: PHP/5.2.0
 Content-type: text/html
 
 Array
 (
 [name] =
 [venue] =
 [description] =
 [errors] = Array
 (
 )
 
 )
 
 
 Andrew

Works great for me also: PHP 5.2.4-2ubuntu5.5 with Suhosin-Patch 0.9.6.2


-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] function array problem

2009-02-17 Thread Eric Butera
On Tue, Feb 17, 2009 at 3:10 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 I've had a bit of a problem with a function I'm using for a form.
 Essentially, the function looks like this:

 function addEvent($values = Array('name' = '', 'venue' = '',
 'description' = '', 'errors' = Array()))
 {
// code here displays the form
 }

 The function is used to both display an empty form, and the form
 populated with values again should there be any validation errors.

 Now this works fine when the form has been filled out and there are
 errors present, as I can call the function with the correct array
 values. However, when I call the function with no arguments (intending
 the function to populate the $values array itself) all it does is
 present me with an empty array. A print_r($values) just returns
 Array( ), no key values defined.

 I altered the function to this:

 function addEvent($values = Array())
 {
if(count($values) == 0)
{
$values = Array('name' = '', 'venue' = '', 'description' =
 '', 'errors' = Array());
}
// code here displays the form
 }

 then all works as intended. Question is, am I being dense, or is there a
 reason why this shouldn't work?


 Ash
 www.ashleysheridan.co.uk


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



Here's how I handle making sure I have the correct structure.

function something(array $array=array()) {
$defs = array('name' = '', 'venue' = '', 'description' ='',
'errors' = Array());
$array = array_merge($defs, $array);

}

-- 
http://www.voom.me | EFnet: #voom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Function, array - problem (probably easy to solve)

2001-03-14 Thread Tobias Talltorp

I am constructing a function for retrieving records from a mysql database
and putting them into an array called $print_field[name][number].

My problem is that I only seem to get the first two records and I think I
know where the problem is, but I canĀ“t seem to be able to solve it.

Any ideas anyone?

?
function print_query_array($query, $fields) {
 global $print_field;
 global $linkid;

  // Determine what fields are selected
  $field = explode("|",$fields);

  $mysql_res = mysql_query($query,$linkid);

  while ($strow = mysql_fetch_array($mysql_res))


   $print_field[$field[0]][] = $strow[$field[0]]; // Problem
   $print_field[$field[1]][] = $strow[$field[1]]; // Problem
  }
}

print_query_array("SELECT field1, field2 FROM table LIMIT 10",
"field1|field2");

for ($i=0; $isizeof($print_field); $i++)

 echo $print_field["field1"][$i]."br";
 echo $print_field["field2"][$i]."br";
}
?

Thanks,
// Tobias





-- 
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]