473,609 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

index an array

oll3i
679 Contributor
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) "applicatio n/msword" } ["file_name"]=> string(63) "09_04_2016.doc " ["file_size"]=> float(143) ["file_type"]=> string(18) "applicatio n/msword" } ["file_name"]=> string(51) "07_04_2016.doc " ["file_size"]=> float(143.5) ["file_type"]=> string(18) "applicatio n/msword" }

How do I index such array in a loop?

Thank You
Jun 5 '16 #1
3 1275
Dormilich
8,658 Recognized Expert Moderator Expert
that array is already indexed.
Jun 6 '16 #2
oll3i
679 Contributor
i meant how do i loop through such array
Jun 6 '16 #3
Dormilich
8,658 Recognized Expert Moderator Expert
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
5172
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
2740
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 (i.e., a matrix) it seems to be trivial, with array indexing, to extract a subset of its *columns*. But it does not seem to be trivial to extract a subset of its *rows*. The code snippet below describes the problem (if it really is a problem)...
9
5705
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: #include<iostream.h> #include<string.h>
10
6741
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 so I could instead reference J with array? I'm pretty new to C++ so have mercy :P iwp506@gmail.com
18
5392
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
2056
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 application in mind, its more academic at this stage - but not a homework question!
6
3628
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,'@','@','@', '@','_','@','@','@','@','@','@','@','@','@', 32,'@','@','@','@', ' ','!','"','#','@','%','&', 39,'(',')','*','+',',','-','.','/', '0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?',...
2
3937
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", "Aa", "Ab", _ "Aba", "B", "Ba", "Bb", "Bba", "BA", "BAa", "BAb", "BAba"} Dim index As Integer
3
5560
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 defines a 1-based array (to be passed to it) ByRef. So as far as I can tell I need to pass it a 1-based array. I'm new to .NET but I've done some homework here and I know that the VB 6.0 "Option Base 1" and like alternatives are no longer supported....
4
1963
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
8109
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8188
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8374
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6034
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5502
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2502
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1630
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.