Re: beginner question on multidimensional arrays
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: beginner question on multidimensional arrays

From: Chung Leong <chernyshevsky@hotmail.com>
Date: Tue Jan 31 2006 - 00:40:22 CET

matthewburton@gmail.com wrote:
> Hi everyone,
>
> I'm trying to write a program that will search a body of text and
> replace certain words (say, A, B, and C) with different words that I
> think are more appropriate (A1, B1 and C1). I have a feeling that I
> need to do this through a multidimensional array. Am I on the right
> track?
>
> thanks,
> matt

I don't really see a need for multidimensional arrays here. A single
associative array would serve perfectly well. For example, the
following is the simplest way to do what you described:

$table = array("A" => "A1", "B" => "B1", "C" => "C1");
$text = strtr($text, $table);

For something requiring more sophisticated handling, you might want to
use preg_replace(), passing twos arrays as parameters.
Received on Tue Feb 7 21:08:03 2006