Re: Question about an array
| From: | Matt Grimm | Date: | Sat, 03 Jan 2004 23:03:31 +0000 |
| Subject: | Re: Question about an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-173697@lists.php.net to get a copy of this message | ||
If you're going to build your array that way, then you need to loop through
$sometext[0], not $sometext. You're creating an array in the first element
of the $sometext array, so $sometext element zero is an array containing
your exploded words.
Instead, try:
$sometext = explode(" ", "your long string");
--
Matt Grimm
Web Developer
The Health TV Channel, Inc.
(a non - profit organization)
3820 Lake Otis Parkway
Anchorage, AK 99508
907.770.6200 ext. 686
907.336.6205 (fax)
E-mail: mgrimm@healthtvchannel.org
Web: www.healthtvchannel.org
"Vernon" <vernon@comp-wiz.com> wrote in message
news:20040103221149.33002.qmail@pb1.pair.com...
> I want to create an array with some text. Let's say the following:
>
> $sometext = array(explode(" ", "Objective: Position as a Machine Attendant
> and or Operator Summary - Over 16 years experience in packaging and
> maintenance of various operating machinery. - 13 years experience in
cutting
> steel and operating a steel press. - Part time experience in packaging and
> shipping bread for a bakery."));
>
> I can easily return that text using:
>
> print_r($sometext);
>
> However I want loop through that text for to bold certain words in the
> array. In any event I've tried using the following but it only returns
> "sometext at[0] is: [Array]" which is not want I want, I want it to show
me
> each word in the array through the loop. Any ideas what I am doing wrong?
>
> $arrayLength = count($sometext);
>
> for ($i = 0; $i < $arrayLength; $i++){
> echo "sometext at[" . $i . "] is: [" .$sometext[$i] .
> "]<br>\n";
> }
>
> Thanks