johced1974 Posted November 2, 2006 Share Posted November 2, 2006 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 More sharing options...
trq Posted November 2, 2006 Share Posted November 2, 2006 Nope.... you'll need to be a bit clearer in your explination. Code doesn't make alot of sense. Link to comment https://forums.phpfreaks.com/topic/25940-array-and-string-problems/#findComment-118466 Share on other sites More sharing options...
johced1974 Posted November 2, 2006 Author Share Posted November 2, 2006 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); Link to comment https://forums.phpfreaks.com/topic/25940-array-and-string-problems/#findComment-118492 Share on other sites More sharing options...
Nicklas Posted November 2, 2006 Share Posted November 2, 2006 It takes it as a string because you made it a string. Link to comment https://forums.phpfreaks.com/topic/25940-array-and-string-problems/#findComment-118533 Share on other sites More sharing options...
johced1974 Posted November 2, 2006 Author Share Posted November 2, 2006 Yeah, I know.Any suggestions on how to keep it as an array? Most appreciated!//Johan Link to comment https://forums.phpfreaks.com/topic/25940-array-and-string-problems/#findComment-118633 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.