本文介绍了如何构建遍历树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究关联数组的树格式:
I am working on tree formatting of an associative array:
Array
(
[8] => Array
(
[name] => David Clance
[email_id] => [email protected]
[designation] => Chief Executive Officer
[member] => Array
(
[62] => Array
(
[name] => Sonali Yadav
[email_id] => [email protected]
[designation] => Managing Director
[member] => Array
(
[1147] => Array
(
[name] => Samina Falgun
[email_id] => [email protected]
[designation] => Associate Technical Product Manager
[member] => Array
(
[676] => Array
(
[name] => Rushi Vyas
[email_id] => [email protected]
[designation] => Team Lead
[member] => Array
(
[946] => Array
(
[name] => Vijay Gade
[email_id] => [email protected]
[designation] => Software Engineer
[member] => Array
(
)
)
[1450] => Array
(
[name] => Shivraj Singh
[email_id] => [email protected]
[designation] => Software Engineer
[member] => Array
(
)
)
)
)
[2748] => Array
(
[name] => Neetha Sunny
[email_id] => [email protected]
[designation] => Software Engineer
[member] => Array
(
[2855] => Array
(
[name] => Celvin Game
[email_id] => [email protected]
[designation] => Software Engineer
[member] => Array
(
)
)
)
)
[1497] => Array
(
[name] => Pranali Dighe
[email_id] => [email protected]
[designation] => Software Engineer
[member] => Array
(
)
)
[3399] => Array
(
[name] => Employee Tue
[email_id] => [email protected]
[designation] => Accounts Officer
[member] => Array
(
)
)
)
)
[2882] => Array
(
[name] => Akash Meheta
[email_id] => [email protected]
[designation] => Manager - Administrations
[member] => Array
(
[972] => Array
(
[name] => Rajendra Gore
[email_id] => [email protected]
[designation] => Office Assistant
[member] => Array
(
)
)
[2925] => Array
(
[name] => Ankush Dadar
[email_id] => [email protected]
[designation] => Office Supervisor
[member] => Array
(
)
)
)
)
)
)
[189] => Array
(
[name] => Dharmendra Shroff
[email_id] => [email protected]
[designation] => Director Of Engineering
[member] => Array
(
[443] => Array
(
[name] => James Bond
[email_id] => [email protected]
[designation] => Software Development Manager
[member] => Array
(
)
)
[1638] => Array
(
[name] => Nilesh Tyagi
[email_id] => [email protected]
[designation] => Associate Manager
[member] => Array
(
[1825] => Array
(
[name] => Asha Das
[email_id] => [email protected]
[designation] => Team Lead
[member] => Array
(
[2561] => Array
(
[name] => Prashant Manere
[email_id] => [email protected]
[designation] => Data Support Executive
[member] => Array
(
)
)
)
)
)
)
)
)
)
)
)
在['member']键的基础上,尝试在父子组中显示树结构,如:
On the basis of ['member'] key, trying to display tree structure in parent-child formation like:
David Clance
Sonali Yadav
Samina Falgun
Rushi Vyas
Vijay Gade
Shivraj Singh
Neetha Sunny
Celvin Game
Pranali Dighe
Employee Tue
Akash Meheta
Rajendra Gore
Ankush Dadar
Dharmendra Shroff
James Bond
Nilesh Tyagi
Asha Das
Prashant Manere
我有类似下面的代码来获取每个数组元素和列数到标签值的递增行数数组:
I have code like below to get the incremented row count for every array element and column count to tab values in array:
<?php
$this->m_intRowCount = 1;
$intColumnCount = 0;
public function handle() {
if( true == valArr( $this->m_arrmixEmployees ) ) {
$this->getEmployeeDetails( $this->m_arrmixEmployees, $intColumnCount );
}
}
public function getEmployeeDetails( $arrmixEmployees, $intColumnCount ) {
foreach( $arrmixEmployees as $keys => $values ) {
$this->m_intRowCount++;
echo $values['name'] . " " . $values['designation'];
if( true == valArr( $values['member'] ) ) {
echo "<br>";
$intColumnCount++;
foreach( $values['member'] as $key => $value ) {
$this->m_intRowCount++;
echo $value['name'] . " " . $value['designation'];
if( true == valArr( $value['member'] ) ) {
echo "<br>";
$intColumnCount++;
$this->getEmployeeDetails( $value['member'], $intColumnCount );
$intColumnCount--;
} else {
echo "<br>";
}
}
} else {
echo "<br>";
continue;
}
}
}
推荐答案
这篇关于如何构建遍历树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!