0

Hi Everyone
I have a problem regarding PHP Array

here is the code:

$array_of_arrays = array(
    array[0] = value1, value2, value3;
    array[1] = value4, value5, value6;
    array[2] = value7, value8, value8;
);

Well i want to skip array[0] in loop. i just want to start the process of loop from array[1] and end at array[2].
and print the value of both array[1] and array[2] only.

to give you an example or what im thinking is that array[0] is the first row of a csv file and the array[1] and array[2] is the second and last row of a csv file.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by blocblue
0

Your array definition isn't quite correct, if you're planning to use that within PHP, rather than defining it for our benefit.

It should be:

$array = array(
    0 => array('value1', 'value2', 'value3'),
    1 => array('value4', 'value5', 'value6'),
    2 => array('value7', 'value8', 'value9'),
);

Where the array keys are optional, but shown for completeness sake.

To iterate over your array, ignoring the first index:

foreach($array as $index => $row) {
    if($index == 0)
        continue;

    foreach($row as $column)
        echo $column . ', ';
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.