Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. if( isset( $array['index'] ) {
  2. //Do something
  3. }
  4.  
  5.  
  6. if( array_key_exists( 'index', $array ) {
  7. //Do something
  8. }
  9.  
  10. $aTestArray = array();
  11.  
  12. echo "Before key is createdrn";
  13. echo "isset:rn";
  14. var_dump( isset( $aTestArray['TestKey'] ) );
  15. echo "array_key_exists:rn";
  16. var_dump( array_key_exists( 'TestKey', $aTestArray ) );
  17. echo "rn";
  18.  
  19. $aTestArray['TestKey'] = NULL;
  20. echo "Key is created, but set to NULLrn";
  21. echo "isset:rn";
  22. var_dump( isset( $aTestArray['TestKey'] ) );
  23. echo "array_key_exists:rn";
  24. var_dump( array_key_exists( 'TestKey', $aTestArray ) );
  25. echo "rn";
  26.  
  27. $aTestArray['TestKey'] = 0;
  28. echo "Key is created, and set to 0 (zero)rn";
  29. echo "isset:rn";
  30. var_dump( isset( $aTestArray['TestKey'] ) );
  31. echo "array_key_exists:rn";
  32. var_dump( array_key_exists( 'TestKey', $aTestArray ) );
  33. echo "rn";
  34.  
  35. Before key is created
  36. isset:
  37. bool(false)
  38. array_key_exists:
  39. bool(false)
  40.  
  41. Key is created, but set to NULL
  42. isset:
  43. bool(false)
  44. array_key_exists:
  45. bool(true)
  46.  
  47. Key is created, and set to 0 (zero)
  48. isset:
  49. bool(true)
  50. array_key_exists:
  51. bool(true)
  52.  
  53. foreach( $array as $key => value )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement