Page 1 of 1

Array issue

Posted: Sat Apr 04, 2009 4:54 am
by tr3online
Hi there,

Say I wanted to save every value of an array on a separate line starting on entry four, for multiple sources of data. The length of the array varies depending on where the data is grabbed from, so it can range anywhere from 10-100. Is there any way to do this?

Example ($matches is the array):

Code: Select all

 
for ( $array_no=4; $array_no<=[color=#40BFFF]max array variable here?[/color]; $array_no=$array_no+1 )
 
{
 
 $line = $matches[1][$array_no];
 fwrite($file, $line."\n");
 
}
 
Thanks!

Re: Array issue

Posted: Sat Apr 04, 2009 6:40 am
by php_east

Code: Select all

$line = '';
for ( $array_no=4; $array_no<=[color=#40BFFF]max array variable here?[/color]; $array_no=$array_no+1 )
{
 $line .= strval($matches[1][$array_no])."\n";
 }
fwrite($file, $line."\n");

Re: Array issue

Posted: Sat Apr 04, 2009 1:46 pm
by tr3online
That doesn't address the last line of the array issue I'm having :\

I basically want to write a file(txt) from $matches[1][4] -> $matches[1][last array value] with a \n in between each $matches

(If the array 31 large, itll go from $matches[1][4]\n -> $matches[1][31]\n)

Re: Array issue

Posted: Sat Apr 04, 2009 2:34 pm
by php_east
what are you saying, that you do not know what the array size is ?
the corrected code loops through all your array items, starting from 4. maybe you want to rephrase your question.
tr3online wrote:(If the array 31 large, itll go from $matches[1][4]\n -> $matches[1][31]\n)
yes, that what it does. what is the problem i don't understand.

Re: Array issue

Posted: Sat Apr 04, 2009 2:38 pm
by php_east
count($matches[1]) ? is that what you are looking for ?

Re: Array issue

Posted: Sat Apr 04, 2009 2:53 pm
by tr3online
count(matches[1]); is exactly what I wanted :)

Thanks a bunch!