mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-08 12:32:42 +00:00
Refactoring and moving countdim() to Set::countDim()
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3840 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
97753554c6
commit
13c579292a
1 changed files with 33 additions and 1 deletions
|
@ -175,9 +175,15 @@ class Set extends Object {
|
||||||
*/
|
*/
|
||||||
function extract($data, $path) {
|
function extract($data, $path) {
|
||||||
if (!is_array($path)) {
|
if (!is_array($path)) {
|
||||||
$path = explode('.', $path);
|
if (strpos($path, '/') !== 0 && strpos($path, './') === false) {
|
||||||
|
$path = explode('.', $path);
|
||||||
|
} else {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$tmp = array();
|
$tmp = array();
|
||||||
|
if (!is_array($path) || empty($path)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
foreach($path as $i => $key) {
|
foreach($path as $i => $key) {
|
||||||
if (intval($key) > 0 || $key == '0') {
|
if (intval($key) > 0 || $key == '0') {
|
||||||
|
@ -201,6 +207,32 @@ class Set extends Object {
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isEqual($val1, $val2 = null) {
|
||||||
|
if ($val2 == null && (is_a($this, 'set') || is_a($this, 'Set'))) {
|
||||||
|
$val2 = $val1;
|
||||||
|
$val1 = $this->get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Counts the dimensions of an array
|
||||||
|
*
|
||||||
|
* @param array $array
|
||||||
|
* @return int The number of dimensions in $array
|
||||||
|
*/
|
||||||
|
function countDim($array = null) {
|
||||||
|
if ($array === null) {
|
||||||
|
$array = $this->get();
|
||||||
|
} elseif (is_object($array) && is_a($array, 'set')) {
|
||||||
|
$array = $array->get();
|
||||||
|
}
|
||||||
|
if (is_array(reset($array))) {
|
||||||
|
$return = Set::countDim(reset($array)) + 1;
|
||||||
|
} else {
|
||||||
|
$return = 1;
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue