本文整理汇总了PHP中dmArray::unsetEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP dmArray::unsetEmpty方法的具体用法?PHP dmArray::unsetEmpty怎么用?PHP dmArray::unsetEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dmArray
的用法示例。
在下文中一共展示了dmArray::unsetEmpty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
$t->is_deeply(dmArray::firsts(array('alpha'), 2), array('alpha'), 'not enough values');
$array = array('alpha', 'beta', 'gamma', 'delta');
$t->is_deeply(dmArray::firsts($array, 2), array('alpha', 'beta'), 'first values');
$t->diag('get');
$t->is_deeply(dmArray::get('alpha', null, 'test'), 'test', 'first parameter is not an array');
$t->is_deeply(dmArray::get(array('alpha'), 0, 'test'), 'alpha', 'key exists');
$t->is_deeply(dmArray::get(array('alpha'), 1, 'test'), 'test', 'key not exists');
$t->is_deeply(dmArray::get(array(''), 0, 'test', false), '', 'empty value without default if empty');
$t->is_deeply(dmArray::get(array(''), 0, 'test', true), 'test', 'empty value with default if empty');
$t->is_deeply(dmArray::get(array('alpha'), 0, 'test', true), 'alpha', 'key exists with default if empty');
$t->diag('last');
$t->is_deeply(dmArray::last('alpha'), 'alpha', 'first parameter is not an array');
$t->is_deeply(dmArray::last(array()), null, 'empty source array');
$array = array('alpha', 'beta', 'gamma', 'delta');
$t->is_deeply(dmArray::last($array), 'delta', 'last value');
$t->diag('toHtmlCssClasses');
$classes = array('class1', '', ' class2', ' ', ' class3 ');
$cleanClasses = 'class1 class2 class3';
$t->is(dmArray::toHtmlCssClasses($classes), $cleanClasses, 'clean classes : ' . $cleanClasses);
$classes = array('class1');
$cleanClasses = 'class1';
$t->is(dmArray::toHtmlCssClasses($classes), $cleanClasses, 'clean classes : ' . $cleanClasses);
$classes = array(' class1 class2 class3 ');
$cleanClasses = 'class1 class2 class3';
$t->is(dmArray::toHtmlCssClasses($classes), $cleanClasses, 'clean classes : ' . $cleanClasses);
$t->diag('unsetEmpty');
$array = array(1 => '', 2 => 'delta', 3 => '', 'alpha' => 'gamma', 'gamma' => '', 'delta' => '');
$t->is_deeply(dmArray::unsetEmpty($array, array(3, 'gamma')), array('1' => '', '2' => 'delta', 'alpha' => 'gamma', 'delta' => ''), 'check');
$t->diag('valueToKey');
$array = array('alpha', 'beta', 'gamma', 'delta');
$t->is_deeply(dmArray::valueToKey($array), array('alpha' => 'alpha', 'beta' => 'beta', 'gamma' => 'gamma', 'delta' => 'delta'), 'check');
示例2: convertAttributesToHtml
protected function convertAttributesToHtml(array $attributes)
{
/*
* Implode classes
*/
if (isset($attributes['class'])) {
$attributes['class'] = dmArray::toHtmlCssClasses($attributes['class']);
}
/*
* Remove non html attributes
*/
foreach ($this->attributesToRemove as $key) {
if (array_key_exists($key, $attributes)) {
unset($attributes[$key]);
}
}
/*
* Remove empty attributes
*/
$attributes = dmArray::unsetEmpty($attributes, $this->emptyAttributesToRemove);
/*
* Convert attributes array into html string params
*/
$htmlAttributesString = '';
foreach ($attributes as $key => $value) {
if (null !== $value) {
$htmlAttributesString .= ' ' . $key . '="' . htmlspecialchars((string) $value, ENT_COMPAT, 'UTF-8') . '"';
}
}
return $htmlAttributesString;
}