RE: [PHP] Array_keys problem

2004-04-06 Thread Ford, Mike [LSS]
On 04 April 2004 01:13, Robin 'Sparky' Kopetzky wrote:

   function key_exists($ps_key)
   {
   if ( in_array($ps_key,
 array_keys($this-ma_arguments)) ) {
 return true;
  } else {
 return false;
  }
   }

Ummm --

   function key_exists($ps_key)
   {
  return array_key_exists($ps_key, this-ma_arguments);
   }

?

(Assuming it's passed the is_array() test, of course!)

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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



Re: [PHP] Array_keys problem

2004-04-04 Thread Burhan Khalid
Robin 'Sparky' Kopetzky wrote:
Good afternoon.

I'm building a class and am having a bunch of trouble with the PHP
array_keys function. I keep getting these errors:
Warning:  First argument to array_keys() should be an array in D:\Htf.php on
line 33
Warning:  Wrong datatype for second argument in call to in_array in
D:\Htf.php on line 35
$this-ma_arguments IS an array, so why is the error popping up? I did check
syntax but am buffaloe'd by this one.
Just so no one gets confused, I use a form of Hungarian (p=parameter,
m=module, a=array, s=string)
Since PHP doesn't have strict typing, you can't be sure what it is.

I've edited your code a bit.

  /**
   * @var assoc array of passed arguments
   */
  //var $ma_arguments;
var $ma_arguments = array();
  /**
   * Constructor
   */
  function bmc_html_tag_functions()
  {
//$this-init();
  }
function init()
{
$this-ma_arguments = array();

}
  /**
   * Checks if the given key or index exists in the array (PHP  4.1.0)
   *
   * @param $ps_keyKey to check against
   * @param $pa_search Array of elements
   * @return true if key is in array
   * @access private
   */
  function key_exists($ps_key)
  {
if (!is_array($this-ma_arguments))
{
echo '$this-ma_arguments is not an array';
echo 'pre'; var_dump($this-ma_arguments); echo '/pre';
if ( in_array($ps_key, array_keys($this-ma_arguments)) ) {
return true;
 } else {
return false;
 }
  }
Try that.

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