Welcome to the Cookbook

loading...

8.5.10 check

boolean/array Set::check ($data, $path = null)

Checks if a particular path is set in an array. If $path is empty, $data will be returned instead of a boolean value.

$set = array(
	'My Index 1' => array('First' => 'The first item')
);
$result = Set::check($set, 'My Index 1.First');
// $result == True
$result = Set::check($set, 'My Index 1');
// $result == True
$result = Set::check($set, array());
// $result == array('My Index 1' => array('First' => 'The first item'))
$set = array(
	'My Index 1' => array('First' => 
		array('Second' => 
			array('Third' => 
				array('Fourth' => 'Heavy. Nesting.'))))
);
$result = Set::check($set, 'My Index 1.First.Second');
// $result == True
$result = Set::check($set, 'My Index 1.First.Second.Third');
// $result == True
$result = Set::check($set, 'My Index 1.First.Second.Third.Fourth');
// $result == True
$result = Set::check($set, 'My Index 1.First.Seconds.Third.Fourth');
// $result == False
  1. $set = array(
  2. 'My Index 1' => array('First' => 'The first item')
  3. );
  4. $result = Set::check($set, 'My Index 1.First');
  5. // $result == True
  6. $result = Set::check($set, 'My Index 1');
  7. // $result == True
  8. $result = Set::check($set, array());
  9. // $result == array('My Index 1' => array('First' => 'The first item'))
  10. $set = array(
  11. 'My Index 1' => array('First' =>
  12. array('Second' =>
  13. array('Third' =>
  14. array('Fourth' => 'Heavy. Nesting.'))))
  15. );
  16. $result = Set::check($set, 'My Index 1.First.Second');
  17. // $result == True
  18. $result = Set::check($set, 'My Index 1.First.Second.Third');
  19. // $result == True
  20. $result = Set::check($set, 'My Index 1.First.Second.Third.Fourth');
  21. // $result == True
  22. $result = Set::check($set, 'My Index 1.First.Seconds.Third.Fourth');
  23. // $result == False