Welcome to the Cookbook

loading...

8.5.13 matches

There is no translation yet for this section. Please help out and translate this.. More information about translations

boolean Set::matches ($conditions, $data=array(), $i = null, $length=null)

Set::matches can be used to see if a single item or a given xpath match certain conditions.

$a = array(
	array('Article' => array('id' => 1, 'title' => 'Article 1')),
	array('Article' => array('id' => 2, 'title' => 'Article 2')),
	array('Article' => array('id' => 3, 'title' => 'Article 3')));
$res=Set::matches(array('id>2'), $a[1]['Article']);
// returns false
$res=Set::matches(array('id>=2'), $a[1]['Article']);
// returns true
$res=Set::matches(array('id>=3'), $a[1]['Article']);
// returns false
$res=Set::matches(array('id<=2'), $a[1]['Article']);
// returns true
$res=Set::matches(array('id<2'), $a[1]['Article']);
// returns false
$res=Set::matches(array('id>1'), $a[1]['Article']);
// returns true
$res=Set::matches(array('id>1', 'id<3', 'id!=0'), $a[1]['Article']);
// returns true
$res=Set::matches(array('3'), null, 3);
// returns true
$res=Set::matches(array('5'), null, 5);
// returns true
$res=Set::matches(array('id'), $a[1]['Article']);
// returns true
$res=Set::matches(array('id', 'title'), $a[1]['Article']);
// returns true
$res=Set::matches(array('non-existant'), $a[1]['Article']);
// returns false
$res=Set::matches('/Article[id=2]', $a);
// returns true
$res=Set::matches('/Article[id=4]', $a);
// returns false
$res=Set::matches(array(), $a);
// returns true

  1. $a = array(
  2. array('Article' => array('id' => 1, 'title' => 'Article 1')),
  3. array('Article' => array('id' => 2, 'title' => 'Article 2')),
  4. array('Article' => array('id' => 3, 'title' => 'Article 3')));
  5. $res=Set::matches(array('id>2'), $a[1]['Article']);
  6. // returns false
  7. $res=Set::matches(array('id>=2'), $a[1]['Article']);
  8. // returns true
  9. $res=Set::matches(array('id>=3'), $a[1]['Article']);
  10. // returns false
  11. $res=Set::matches(array('id<=2'), $a[1]['Article']);
  12. // returns true
  13. $res=Set::matches(array('id<2'), $a[1]['Article']);
  14. // returns false
  15. $res=Set::matches(array('id>1'), $a[1]['Article']);
  16. // returns true
  17. $res=Set::matches(array('id>1', 'id<3', 'id!=0'), $a[1]['Article']);
  18. // returns true
  19. $res=Set::matches(array('3'), null, 3);
  20. // returns true
  21. $res=Set::matches(array('5'), null, 5);
  22. // returns true
  23. $res=Set::matches(array('id'), $a[1]['Article']);
  24. // returns true
  25. $res=Set::matches(array('id', 'title'), $a[1]['Article']);
  26. // returns true
  27. $res=Set::matches(array('non-existant'), $a[1]['Article']);
  28. // returns false
  29. $res=Set::matches('/Article[id=2]', $a);
  30. // returns true
  31. $res=Set::matches('/Article[id=4]', $a);
  32. // returns false
  33. $res=Set::matches(array(), $a);
  34. // returns true