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 68a5937 commit 179f042
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/SplArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,33 @@ function get($path)
$paths = explode(".", $path);
$data = $this->getArrayCopy();
while ($key = array_shift($paths)){
if(isset($data[$key])){
$data = $data[$key];
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{
return null;
if(isset($data[$key])){
$data = $data[$key];
}else{
return null;
}
}
}
return $data;
Expand Down

0 comments on commit 179f042

Please sign in to comment.