$info=m (' Navclass ')Select ();functionGetallarray ($data,$pid=1) { $arr=Array(); foreach($data as $v) { if($v[' f_id ']==$pid){ $arr[] =$v[' ID ']; $arr=Array_merge($arr, Getallarray ($data,$v[' ID '])); } } //foreach ($data as $k = + $v) {//if ($v [' f_id '] = = $pid) {//$v [' child '] = Getallarray ($data, $v [' ID ']);//$arr [] = $v;///} Here is a merge for the array//} return $arr; } $info= Getallarray ($info); Print_r($info);
Merging arrays in PHP is divided into two cases
1, if the two arrays have the same string key name:
$book 1 = array (' Linux ' + ' Linux server configuration and Management ', ' php ' = ' php programming ');
$book 2 = Array (' Linux ' = ' Server configuration and Management ', ' jsp ' = ' PHP ');
$result = Array_merge ($book 1, $book 2);
Print_r ($result);
?>The output is:Array ([Linux] = server configuration and management [PHP] + PHP programming [JSP] + PHP)
the latter will replace the former. However, if you are using array_merge_recursive (), you can persist and make a subarray exist. Such as:
$book 1 = array (' Linux ' + ' Linux server configuration and Management ', ' php ' = ' php programming ');
$book 2 = Array (' Linux ' = ' Server configuration and Management ', ' jsp ' = ' PHP ');
$result = array_merge_recursive ($book 1, $book 2);
Print_r ($result);
?>The output is:array ([Linux] = = Array ([0] = + Linux server configuration and management [1] = + server configuration and Management) [PHP] + PHP programming [JSP] + PHP)
2, if the two arrays have the same numeric key name:
$book 1 = array (' Linux server Configuration and Management ', ' PHP programming ');
$book 2 = Array (' Server configuration and Management ', ' PHP ');
$result = Array_merge ($book 1, $book 2);
Print_r ($result);
?>The result is:Array ([0] = + Linux server configuration and management [1] + PHP programming [2] + = Server configuration and management [3] = PHP)
At this point, if the array contains the same numeric key name, then the previous value is not overwritten, but the subsequent key values are incremented sequentially, appended to the back. Do you understand, ^_^
The use of recursive functions and the use of Array_merge