php - 在 PHP 中使动态树视图引导程序适应我的 BDD
问题描述
我对 php 数组有疑问。我终于想要一个这样的数组。这是我需要的:
$arr = [
[
'text' => '2018-11-01>123456>cassa',
'nodes' => [
[
'text' => '32weds>has>aaaaa',
'nodes' => [
[
'text' => '32.png',
],
],
],
[
'text' => 'aegergert24562>han>asdfsd',
'nodes' => [
[
'text' => '32(1).png',
],
],
],
],
],
[
'text' => '2018-11-02>1234>cassa',
'nodes' => [
[
'text' => 'qwerty>has>aaaaa',
'nodes' => [
[
'text' => 'rr.png',
],
],
],
[
'text' => 'sDFSDF>ha>aaaaa',
'nodes' => [
[
'text' => 'ff.png',
],
],
],
],
],
];
$data = $arr;
echo json_encode($data);
所以我的几个测试的php代码如下:
$query = " SELECT * FROM saisie order by date, n_trans, destination, n_fact, client, transitaire ";
$result = mysqli_query($connect, $query);
while ($row = mysqli_fetch_array($result)) {
$sub_data["code"] = $row["code"];
$sub_data["text"] = $row["date"] . '>' . $row["n_trans"] . '>' . $row["destination"];
$sub_data["text1"] = $row["n_fact"] . '>' . $row["client"] . '>' . $row["transitaire"];
$sub_data["nom_doc"] = $row["nom_doc"];
$data[] = $sub_data;
}
$output = array();
foreach ($data as &$value) {
$id = $value['text'];
$id1 = $value['text1'];
if (!isset($id)) {
if (!array_key_exists($value['text1'], $output)) {
$output[$id1] = array(
'text' => $id1,
'nodes' => array()
);
}
$output[$id1]['text'] = &$value;
} else {
if (!array_key_exists($value['text'], $output)) {
$output[$id] = array(
'text' => $id,
'nodes' => array()
);
}
$output[$id]['nodes'][$id1] = &$value;
}
}
而且由于我的阵列不是很强大,所以我无法达到相同的结果。
解决方案
推荐阅读
- angular - 使用 Angular + Nativescript 模板将数据与 RadListView 绑定的正确方法是什么?
- symfony - 如何使用 Doctrine2 在扩展实体中添加索引?
- java - 骆驼。两个线程同时处理相同的消息
- node.js - SQL 'UNION ALL' 类似 MongoDB 中的实现
- javascript - React js:event.preventDefault 为 react-boostrap menuItem 抛出异常
- reactjs - 无法获取/更改存储值 -REDUX (React Native)
- c# - C# reg express:如何从数字中删除括号
- c# - 如何使用实体框架将 RichTextBox 内容存储到 WPF 中的 SQLServer 数据库
- c# - 在 Visual Studio 中将类显示为 .cs 而不是类的子级
- java - 找到多个文件,其独立于操作系统的路径为“org/cyberneko/html/res/ErrorMessages_ja.txt”