Jump to content

Array and string problems


johced1974

Recommended Posts

I'm getting some data from a table and therefore have a variable amount of data being returned. The following works:

$data = array(array('company'=>'Company 1'),array('company'=>'Company 2'),array('company'=>'Company 3'));

But when I want the contents as a variable it doens't work. See following:

$myContent = "array('company'=>'Company 1'),array('company'=>'Company 2'),array('company'=>'Company 3')";
$data = array($myContent);

I'm guessing that it thinks my $data above is a string but I'm not sure how to get to understand.
Link to comment
https://forums.phpfreaks.com/topic/25940-array-and-string-problems/
Share on other sites

Hi again,

OK. I've got an array with the following value:
---------------------------------------
$data = array(
  array('company'=>'Company 1'),
  array('company'=>'Company 2'),
  array('company'=>'Company 3')
);

And it works just fine. But if I put the contents into a variable called $myContents it doesn't work. I think it sees the contents as a text string.

This is what I want but it doesn't echo anything:
---------------------------------------
$myContent = "
array('company'=>'Company 1'),
array('company'=>'Company 2'),
array('company'=>'Company 3')
";

$data = array($myContent);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.