Skip to content

Commit

Permalink
支持*搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Mar 15, 2019
1 parent 179f042 commit 2848daa
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/SplArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,30 @@ function get($path)
$paths = explode(".", $path);
$data = $this->getArrayCopy();
while ($key = array_shift($paths)){
if($key == '*'){
$temp = [];
if(is_array($data)){
if(!empty($paths)){
$path = implode("/",$paths);
}else{
$path = null;
}
foreach ($data as $key => $datum){
if(is_array($datum)){
$ctemp = (new SplArray($datum))->get($path);
if($ctemp !== null){
$temp[][$path] = $ctemp;
}
}else if($datum !== null){
$temp[$key] = $datum;
if(isset($data[$key])){
$data = $data[$key];
}else{
if($key == '*'){
$temp = [];
if(is_array($data)){
if(!empty($paths)){
$path = implode("/",$paths);
}else{
$path = null;
}
foreach ($data as $key => $datum){
if(is_array($datum)){
$ctemp = (new SplArray($datum))->get($path);
if($ctemp !== null){
$temp[][$path] = $ctemp;
}
}else if($datum !== null){
$temp[$key] = $datum;
}

}
}
}
return $temp;
}else{
if(isset($data[$key])){
$data = $data[$key];
return $temp;
}else{
return null;
}
Expand Down

0 comments on commit 2848daa

Please sign in to comment.