Welcome to the Cookbook

loading...

8.5.6 normalize

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

array Set::normalize ($list, $assoc = true, $sep = ',', $trim = true)

Normalizes a string or array list.

$a = array('Tree', 'CounterCache',
		'Upload' => array(
			'folder' => 'products',
			'fields' => array('image_1_id', 'image_2_id', 'image_3_id', 'image_4_id', 'image_5_id')));
$b =  array('Cacheable' => array('enabled' => false),
		'Limit',
		'Bindable',
		'Validator',
		'Transactional');
$result = Set::normalize($a);
/* $result now looks like:
	Array
	(
	    [Tree] => 
	    [CounterCache] => 
	    [Upload] => Array
	        (
	            [folder] => products
	            [fields] => Array
	                (
	                    [0] => image_1_id
	                    [1] => image_2_id
	                    [2] => image_3_id
	                    [3] => image_4_id
	                    [4] => image_5_id
	                )
	        )
	)
*/
$result = Set::normalize($b);
/* $result now looks like:
	Array
	(
	    [Cacheable] => Array
	        (
	            [enabled] => 
	        )

	    [Limit] => 
	    [Bindable] => 
	    [Validator] => 
	    [Transactional] => 
	)
*/
$result = Set::merge($a, $b); // Now merge the two and normalize
/* $result now looks like:
	Array
	(
	    [0] => Tree
	    [1] => CounterCache
	    [Upload] => Array
	        (
	            [folder] => products
	            [fields] => Array
	                (
	                    [0] => image_1_id
	                    [1] => image_2_id
	                    [2] => image_3_id
	                    [3] => image_4_id
	                    [4] => image_5_id
	                )

	        )
	    [Cacheable] => Array
	        (
	            [enabled] => 
	        )
	    [2] => Limit
	    [3] => Bindable
	    [4] => Validator
	    [5] => Transactional
	)
*/
$result = Set::normalize(Set::merge($a, $b));
/* $result now looks like:
	Array
	(
	    [Tree] => 
	    [CounterCache] => 
	    [Upload] => Array
	        (
	            [folder] => products
	            [fields] => Array
	                (
	                    [0] => image_1_id
	                    [1] => image_2_id
	                    [2] => image_3_id
	                    [3] => image_4_id
	                    [4] => image_5_id
	                )

	        )
	    [Cacheable] => Array
	        (
	            [enabled] => 
	        )
	    [Limit] => 
	    [Bindable] => 
	    [Validator] => 
	    [Transactional] => 
	)
*/
  1. $a = array('Tree', 'CounterCache',
  2. 'Upload' => array(
  3. 'folder' => 'products',
  4. 'fields' => array('image_1_id', 'image_2_id', 'image_3_id', 'image_4_id', 'image_5_id')));
  5. $b = array('Cacheable' => array('enabled' => false),
  6. 'Limit',
  7. 'Bindable',
  8. 'Validator',
  9. 'Transactional');
  10. $result = Set::normalize($a);
  11. /* $result now looks like:
  12. Array
  13. (
  14. [Tree] =>
  15. [CounterCache] =>
  16. [Upload] => Array
  17. (
  18. [folder] => products
  19. [fields] => Array
  20. (
  21. [0] => image_1_id
  22. [1] => image_2_id
  23. [2] => image_3_id
  24. [3] => image_4_id
  25. [4] => image_5_id
  26. )
  27. )
  28. )
  29. */
  30. $result = Set::normalize($b);
  31. /* $result now looks like:
  32. Array
  33. (
  34. [Cacheable] => Array
  35. (
  36. [enabled] =>
  37. )
  38. [Limit] =>
  39. [Bindable] =>
  40. [Validator] =>
  41. [Transactional] =>
  42. )
  43. */
  44. $result = Set::merge($a, $b); // Now merge the two and normalize
  45. /* $result now looks like:
  46. Array
  47. (
  48. [0] => Tree
  49. [1] => CounterCache
  50. [Upload] => Array
  51. (
  52. [folder] => products
  53. [fields] => Array
  54. (
  55. [0] => image_1_id
  56. [1] => image_2_id
  57. [2] => image_3_id
  58. [3] => image_4_id
  59. [4] => image_5_id
  60. )
  61. )
  62. [Cacheable] => Array
  63. (
  64. [enabled] =>
  65. )
  66. [2] => Limit
  67. [3] => Bindable
  68. [4] => Validator
  69. [5] => Transactional
  70. )
  71. */
  72. $result = Set::normalize(Set::merge($a, $b));
  73. /* $result now looks like:
  74. Array
  75. (
  76. [Tree] =>
  77. [CounterCache] =>
  78. [Upload] => Array
  79. (
  80. [folder] => products
  81. [fields] => Array
  82. (
  83. [0] => image_1_id
  84. [1] => image_2_id
  85. [2] => image_3_id
  86. [3] => image_4_id
  87. [4] => image_5_id
  88. )
  89. )
  90. [Cacheable] => Array
  91. (
  92. [enabled] =>
  93. )
  94. [Limit] =>
  95. [Bindable] =>
  96. [Validator] =>
  97. [Transactional] =>
  98. )
  99. */