简体   繁体   中英

Create multidimensional array in php

I have a resource table which contains columns ID,resourceID(foreign key of another table),date,filename .I need to display the contents of the database table in a table. The structure of table is like this:

ID     resourceID    date         filename
 1        23         20-1-2015      abc.txt
 2        23         20-1-2015      xyz.jpg
 3        24         21-1-2015      tt.png
......

I need to display the files for the resourceID = 23 in a single row(for me its coming in 2 rows for resourceID=23 since it has two files).I have created a multi dimensional array for displaying the resources like this.

$array_uploaded_files=array();
$array_uploaded_files[$data['resourceID']]=   array($data['resourceID']=>$data['filename']);

since I am newbie in multidimensional arrays I am not getting the correct result.Thanks in advance

<?php
$index=0;
foreach ($data as &$item)
    if($item["resourceID"]==23)
    {
        $array_uploaded_files[$index] = 
            array(
                'resourceID'=>$item['resourceID'],
                'filename'=>$item['filename']
                );
        index++;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM