I have been trying to figure out how to populate a html template with data from a multi dimensional array, but i cant figure it out. The template is taken from MySQL.

This is what I have:

$template=addslashes($row['content']);

eval("\$body=\"$template\";");

print($body);

Now the template is as follows:

$row['content'] = "<html><p>array item one $arr[0][0]</p><p>array item two $arr[0][1]</p></html>"

...and the array ($arr):

Array ( [0] => Array ( [0] => 1 [1] => 6 ) )

The result is:

$body = <html><p>array item one Array[0]</p><p>array item two Array[1]</p></html>

...as opposed to what I expected:

$body = <html><p>array item one 1</p><p>array item two 6</p></html>

I can get this to work fine with 'solo variables' but it just wont return 'array variables'...

Anyone have any ideas where I am going wrong? I appologise in advance for my limited knowledge, im still learning. :)

Recommended Answers

All 2 Replies

Member Avatar for diafol

You need to change the template anyhow:

//$arr set previously;

//$template = "<html><p>array item one {$arr[0][0]}</p><p>array item two {$arr[0][1]}</p></html>";

echo $template;

Aha! You are right. Thanks for your help, I knew it would be something simple.

Solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.