Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在数组中正确组织我的数据库结果?_Php_Database_Algorithm_Multidimensional Array_Data Structures - Fatal编程技术网

Php 如何在数组中正确组织我的数据库结果?

Php 如何在数组中正确组织我的数据库结果?,php,database,algorithm,multidimensional-array,data-structures,Php,Database,Algorithm,Multidimensional Array,Data Structures,我想在代码中正确地组织我的数据库结果,这样我就可以有效地处理这些结果,而不会有太多混乱。 例如 id type prop value image_path is_primary 28 Leasable space Total built up area 1

我想在代码中正确地组织我的数据库结果,这样我就可以有效地处理这些结果,而不会有太多混乱。 例如


id          type               prop            value               image_path                                                                 is_primary
28  Leasable space  Total built up area        10001            https://development-stockarea.s3.ap-south-1.amazonaws.com/images/W-00000001-0.jpeg  1
28  Leasable space  Warehouse Identifier    TEST_ARJUN          https://development-stockarea.s3.ap-south-1.amazonaws.com/images/W-00000001-0.jpeg  1
29  Leasable space  Warehouse Identifier    TEST_ARJUN1         https://development-stockarea.s3.ap-south-1.amazonaws.com/images/W-00000001-1.JPG   1
29  Leasable space  Total built up area        1001             https://development-stockarea.s3.ap-south-1.amazonaws.com/images/W-00000001-1.JPG   1


这是我获取的数据。现在,根据主键(id),我想制作合适的数组结构。它将是多维度的

arr[28][type]=Leasable Space
arr[28][prop][warehouseidentifier]=test_arjun
arr[28][prop][total built up area]=10001
因此,我无法形成一种方法,如何在没有任何混乱的情况下有效地构建这个结构。或者有什么好的图书馆可以帮助我这样做。
任何帮助都将不胜感激

像这样的东西应该可以满足您的需要:

$arr = array();
while ($row = $result->fetch_assoc()) {
    $arr[$row['id']]['type'] = $row['type'];
    $arr[$row['id']]['prop'][$row['prop']] = $row['value'];
}

你尝试了什么?你好,很好,谢谢你的回复。我正在从codeigniter获取$result数组,并且它对数组上的成员函数fetch_assoc()的调用显示了错误。@AbhirajTulsyan如果您的数据已经存在于关联结果数组中,您应该能够只使用
foreach($result as$row){
而不是
while($row=$result->fetch_assoc()){ < /代码> @ AbhirajTulsyan回答了你的问题吗?如果不是,你能提供更多的信息来帮助回答吗?否则,请考虑标记接受的答案(在上/下投票箭头下的复选标记)。