473,320 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

index an array

oll3i
679 512MB
Hi,

Expand|Select|Wrap|Line Numbers
  1. var_dump($files)
  2.  
returns

array(4) { [0]=> array(4) { [0]=> array(4) { [0]=> array(0) { } ["file_name"]=> string(51) "01_04_2016.doc" ["file_size"]=> float(138) ["file_type"]=> string(18) "application/msword" } ["file_name"]=> string(63) "09_04_2016.doc" ["file_size"]=> float(143) ["file_type"]=> string(18) "application/msword" } ["file_name"]=> string(51) "07_04_2016.doc" ["file_size"]=> float(143.5) ["file_type"]=> string(18) "application/msword" }

How do I index such array in a loop?

Thank You
Jun 5 '16 #1
3 1262
Dormilich
8,658 Expert Mod 8TB
that array is already indexed.
Jun 6 '16 #2
oll3i
679 512MB
i meant how do i loop through such array
Jun 6 '16 #3
Dormilich
8,658 Expert Mod 8TB
usually you would loop through an array using foreach, but your array is created in an odd way that makes it hard to use.

your array with indentation
Expand|Select|Wrap|Line Numbers
  1. array(4) { 
  2.     [0]=> array(4) { 
  3.         [0]=> array(4) { 
  4.             [0]=> array(0) { 
  5.             } 
  6.             ["file_name"]=> string(51) "01_04_2016.doc" 
  7.             ["file_size"]=> float(138) 
  8.             ["file_type"]=> string(18) "application/msword" 
  9.         } 
  10.         ["file_name"]=> string(63) "09_04_2016.doc" 
  11.         ["file_size"]=> float(143) 
  12.         ["file_type"]=> string(18) "application/msword" 
  13.     } 
  14.     ["file_name"]=> string(51) "07_04_2016.doc" 
  15.     ["file_size"]=> float(143.5) 
  16.     ["file_type"]=> string(18) "application/msword" 
  17. }
as you can see, the data are put into different levels, which make it hard to work with. it would be easier to have the data in a more sensibly organised way, e.g.
Expand|Select|Wrap|Line Numbers
  1. array(3) { 
  2.     [0]=> array(3) { 
  3.         ["file_name"]=> string(51) "01_04_2016.doc" 
  4.         ["file_size"]=> float(138) 
  5.         ["file_type"]=> string(18) "application/msword" 
  6.     } 
  7.     [1]=> array(3) { 
  8.         ["file_name"]=> string(63) "09_04_2016.doc" 
  9.         ["file_size"]=> float(143) 
  10.         ["file_type"]=> string(18) "application/msword" 
  11.     } 
  12.     [2]=> array(3) { 
  13.         ["file_name"]=> string(51) "07_04_2016.doc" 
  14.         ["file_size"]=> float(143.5) 
  15.         ["file_type"]=> string(18) "application/msword" 
  16.     }
  17. }
eventually, I recommend to fixd this' array creation before you proceed with the array data.
Jun 6 '16 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
6
by: Michael Drumheller | last post by:
(If you're not interested in NumArray, please skip this message.) I am new to NumArray and I wonder if someone can help me with array-indexing. Here's the basic situation: Given a rank-2 array...
9
by: Acacia | last post by:
i get this error on any line with dot notation. Oh, and do I need to use cin.getline(boy.name)?: error:'.':left operand points to 'struct' use '->' This is the program in question: ...
10
by: IWP506 | last post by:
Hey, I'd like to make an array with one index for each letter of the alphabet. OK, easy enough. But instead of referencing the letter J with array, can I enumerate every letter with A being 1...
18
by: Joshua Neuheisel | last post by:
The following code compiles with gcc 3.2.2 and Visual C++ 6: #include <stdio.h> int main() { int a = {3, 4}; printf ("%d\n", 0); return 0; }
1
by: Hal Styli | last post by:
hello, can someone please help... Im interested in the use of an auxiliary array to act like pointers for another array, allowing the sort order to be traversed. See code below. I dont have an...
6
by: Anjali | last post by:
Hi, I am handling an array with a hexadecimal index for the first time. What actually does the below means. arr = { '@','£','$','@','@','@','@','@','@','@', 10,'@', 13,'@','@','@',...
2
by: Mario | last post by:
Hi there, I'm writing a piece of code with VS.Net 2003, Framework 1.1. And I can't make BinarySearch to work right. Look at this sample: Dim sexy() As String = {"-", "a", "b", "ba", "A",...
3
by: John Dolan | last post by:
Hi all, I need some help here. I have an ActiveX object that requires me to pass in an array that is 1-based (as opposed to the normal 0-based index). Unfortunately the author of the ActiveX...
4
by: Jay G. Scott | last post by:
this should be trivial, yet i can't find it in a tutorial. int AAA; int BBB; i want to call f(AAA,12,234) and f(BBB,98,2478). how should f be declared? int f( huh?, int ll, int rr)
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.