Simply Program

Simply programming - It’s a life style

Archive for ...

Filed under Programming, PHP

This is quite a unique little function. It came in handy when I had to check a "global" array holding all key elements already loaded.

CODE:
  1. $foo = array('test1'=>"This is test 1",
  2.  
  3. 'test2'=>"This is test 2");
  4.  
  5. $global_bar = array('test1'=>'yep its loaded');
  6.  
  7. foreach($foo as $fkey=>$f){
  8.  
  9. if(!array_key_exists($fkey, $global_bar)){
  10.  
  11. // not there - keep going.
  12.  
  13. }else{
  14.  
  15. // Yep its there.
  16.  
  17. }
  18.  
  19. }

Very simple example above - for more information check php.net: http://www.php.net/manual/en/function.array-key-exists.php

Comments (0) Posted by sp on Friday, April 18th, 2008