Skip to main content

check_key()

public function check_key( $key )

This method checks to see if a passed value is set and is not empty. If both conditions are met, the method returns true. Otherwise, the method returns false.


Arguments#

  • $key
    (string) (required) The variable to evaluate.

Example#

Take the following code:

$my_array = array(
'title' => 'My Awesome Title',
'content' => '',
);
$check1 = $this->check_key( $my_array['title'] );
$check2 = $this->check_key( $my_array['content'] );
$check3 = $this->check_key( $my_array['image_id'] );

In the example above:

  • $check1 would equal true
  • $check2 would equal false
  • $check3 would equal false