Reply to Re: [PHP] Re: array_slice and for loop problem

Your name:

Reply:


Posted by Rodney Green on 10/13/05 15:38

$output[] = array_slice ($textArray, $int_range[start][$i],
$int_range[end][$i]); is creating a multi-dimensional array as
$output. In my foreach loop I was treating $output as a
single-dimensional array. That's why it wasn't working. print_r() is
my friend. :-)


On 10/13/05, Rodney Green <rodgreen@gmail.com> wrote:
> Thanks Connor. I changed the line to the following. Is it correct now?
> The array $output[] is now being populated. However, when I go to
> print the values of the $output array using a foreach loop, it prints
> out the word "Array" for each array item.
>
> $output[] = array_slice ($textArray, $int_range[start][$i],
> $int_range[end][$i]);
>
>
>
> On 10/12/05, Ethilien <spam@ethilien.info> wrote:
> > Are you trying to put each return from array_slice into $output as an
> > array? You need to replace $output = array_slice... with $output[] =
> > array_slice...
> >
> > Also, you cannot just echo an array (even of characters). It must be a
> > string, or else echo will only produce the output 'Array'.
> >
> > Hope this helps,
> > -Connor McKay
> >
> > Rodney Green wrote:
> > > Hello,
> > >
> > > I'm using a for loop to iterate through an array and slice parts of
> > > the array and add into another array.
> > >
> > > When array_slice is called the variable $i is not being substituted
> > > with the current value of
> > > $i and the $output array is empty after running the script. Can
> > > someone look at the code below and give me a clue as to why this
> > > substitution is not happening? If I uncomment the "echo $i;" statement
> > > the value of $i is printed just fine.
> > >
> > > Thanks,
> > > Rod
> > >
> > > Here's my code:
> > >
> > >
> > > $number = count ($int_range[start]);
> > > //echo $number;
> > > for ($i = 0; $i <= $number; $i++) {
> > >
> > > //echo $i;
> > >
> > > $output = array_slice ($textArray, $int_range[start][$i],
> > > $int_range[end][$i]);
> > >
> > > }
> > >
> > >
> > >
> > >
> > > foreach ($output as $value) {
> > >
> > > echo $value;
> > > }
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
> --
> There are 10 kinds of people in this world: those who understand
> binary data, and those who
> don't.
>
> -------------------------------------------------------
> Get Firefox Web Browser at the link below! You won't regret it!
> http://tinyurl.com/4cqbv
>


--
There are 10 kinds of people in this world: those who understand
binary data, and those who
don't.

-------------------------------------------------------
Get Firefox Web Browser at the link below! You won't regret it!
http://tinyurl.com/4cqbv

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация