Page 1 of 1
Multi-Dimensional Array Help
Posted: Mon Jan 13, 2014 2:10 pm
by Xaos
Code: Select all
$gap = array(
array(1,'status'),
array(2,'status'),
array(3,'status'),
array(4,'status'),
array(5,'status'),
array(6,'status'),
array(7,'status'),
array(8,'status'),
array(9,'status'),
array(10,'status'),
);
So I have this array. I want to check all of the numerical values to another value, and I want to check the second value to a
String. I know I can use a for loop for a normal array, but not sure how for a multidimensional. Thanks for help

Re: Multi-Dimensional Array Help
Posted: Mon Jan 13, 2014 3:34 pm
by hallsofvallhalla
in the current example I am not sure why your first value needs to be numbers, just use indexes unless of course your index will not match the number. $gap[1] = 'status'
otherwise
Code: Select all
for(var i =0; i<gap.length;i++)
{
for(var l=0;l<gap[i].length;l++)
{
console.log(gap[i][l];
}
}
Re: Multi-Dimensional Array Help
Posted: Mon Jan 13, 2014 4:16 pm
by Xaos
Oh man, I hadn't even thought of using just the index as the gap. Thanks for that, and the solution to the multi-problem.
Oh,another relating problem. For some reason, I tried to use $gap.length for the loop but it gave me an error, so I had to do count($gap); what was I doing wrong?
Re: Multi-Dimensional Array Help
Posted: Mon Jan 13, 2014 5:27 pm
by hallsofvallhalla
you are using PHP? I am using javascript above.