Styles2304 Posted November 20, 2008 Share Posted November 20, 2008 I don't think this is a hard fix I just don't know enough to know what to look for so here goes. The Array: ----------------------- Array ( [PageTitle] => Celebrate Recovery [HeaderImage] => blahblahblah.png [introduction] => Array ( [FontColor] => #000000 [Content] => this is a test ) [NumberOfBlocks] => 2 [blocks] => Array ( [0] => "Block1" => array("FontColor" => "#000000", "INavYN" => "1", "DNavYN" => "1", "Title" => "Test Title", "Content" => "This is test content"), "Block2" => array("FontColor" => "#000000", "INavYN" => "1", "DNavYN" => "1", "Title" => "Test Title", "Content" => "This is test content") ) ) ----------------------- I'm trying to populate the array like so: <?php $BlockArray = array("PageTitle" => "$PageTitle", "HeaderImage" => "$HeaderImage", "Introduction" => array("FontColor" => "$IntroColor", "Content" => "$IntroContent"), "NumberOfBlocks" => $NumBlocks, "Blocks" => array($BlockOutput)); ?> The problem is in the blocks array, it isn't processing the $BlockOutput string as array data. So, my question is how do I get the array to read the array data in the string and process it properly? Quote Link to comment https://forums.phpfreaks.com/topic/133436-solved-array-trouble/ Share on other sites More sharing options...
foxtrotwhiskey Posted November 20, 2008 Share Posted November 20, 2008 What is generating $BlockOutput? You can't pass a string with array php code to array(). It will just make it an array with one element that is the string you passed to it. Quote Link to comment https://forums.phpfreaks.com/topic/133436-solved-array-trouble/#findComment-694034 Share on other sites More sharing options...
foxtrotwhiskey Posted November 20, 2008 Share Posted November 20, 2008 So it looks like to me that $BlockOutput is: <?php $BlockOutput = '"Block1" => array("FontColor" => "#000000", "INavYN" => "1", "DNavYN" => "1", "Title" => "Test Title", "Content" => "This is test content"), "Block2" => array("FontColor" => "#000000", "INavYN" => "1", "DNavYN" => "1", "Title" => "Test Title", "Content" => "This is test content")'; ?> For whatever reason. Why are you doing it this way? Quote Link to comment https://forums.phpfreaks.com/topic/133436-solved-array-trouble/#findComment-694045 Share on other sites More sharing options...
networkthis Posted November 20, 2008 Share Posted November 20, 2008 Celebrate Recovery -->>> sorry just curious your not in illinois are you??? Quote Link to comment https://forums.phpfreaks.com/topic/133436-solved-array-trouble/#findComment-694073 Share on other sites More sharing options...
Styles2304 Posted November 20, 2008 Author Share Posted November 20, 2008 No, I'm in Indiana. This is for a web editor and $BlockOutput is Dynamic. The user selects how many "blocks" they want on their page so when I'm creating the array, it could be 1 block, it would be 24. So how would I convert the string data to something that can be put into an arrray? Quote Link to comment https://forums.phpfreaks.com/topic/133436-solved-array-trouble/#findComment-694232 Share on other sites More sharing options...
Styles2304 Posted November 20, 2008 Author Share Posted November 20, 2008 Well, I've also tried making the entire array one string to no avail. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/133436-solved-array-trouble/#findComment-694279 Share on other sites More sharing options...
kenrbnsn Posted November 20, 2008 Share Posted November 20, 2008 You have to re-think how you're generating that string. If you give us a hint how you're doing it now, we could help you find a better solution. Ken Quote Link to comment https://forums.phpfreaks.com/topic/133436-solved-array-trouble/#findComment-694290 Share on other sites More sharing options...
Styles2304 Posted November 20, 2008 Author Share Posted November 20, 2008 Alrighty, here she is: <?php while ($BlockCounter <= $NumBlocks) { $BlockName = 'Block' . $BlockCounter; $BlockFColor = $_POST[$BlockName . 'FColor']; $BlockINavYN = $_POST[$BlockName . 'INavYN']; $BlockDNavYN = $_POST[$BlockName . 'DNavYN']; $BlockTitle = $_POST[$BlockName . 'Title']; $BlockContent = $_POST[$BlockName . 'Content']; $BlockOutput .=<<<EOD "$BlockName" => array("FontColor" => "$BlockFColor", "INavYN" => "$BlockINavYN", "DNavYN" => "$BlockDNavYN", "Title" => "$BlockTitle", "Content" => "$BlockContent") EOD; if ($BlockCounter != $NumBlocks) { $BlockOutput .=<<<EOD , EOD; } $BlockCounter++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/133436-solved-array-trouble/#findComment-694304 Share on other sites More sharing options...
sasa Posted November 20, 2008 Share Posted November 20, 2008 try <?php while ($BlockCounter <= $NumBlocks) { $BlockName = 'Block' . $BlockCounter; $BlockFColor = $_POST[$BlockName . 'FColor']; $BlockINavYN = $_POST[$BlockName . 'INavYN']; $BlockDNavYN = $_POST[$BlockName . 'DNavYN']; $BlockTitle = $_POST[$BlockName . 'Title']; $BlockContent = $_POST[$BlockName . 'Content']; $BlockOutput[$BlockName]= array("FontColor" => "$BlockFColor", "INavYN" => "$BlockINavYN", "DNavYN" => "$BlockDNavYN", "Title" => "$BlockTitle", "Content" => "$BlockContent"); $BlockCounter++; } ?> and <?php $BlockArray = array("PageTitle" => "$PageTitle", "HeaderImage" => "$HeaderImage", "Introduction" => array("FontColor" => "$IntroColor", "Content" => "$IntroContent"), "NumberOfBlocks" => $NumBlocks, "Blocks" => $BlockOutput); ?> Quote Link to comment https://forums.phpfreaks.com/topic/133436-solved-array-trouble/#findComment-694476 Share on other sites More sharing options...
Styles2304 Posted November 20, 2008 Author Share Posted November 20, 2008 It works . . . but I have no idea why. Is there a tutorial somewhere that will explain that? Quote Link to comment https://forums.phpfreaks.com/topic/133436-solved-array-trouble/#findComment-694512 Share on other sites More sharing options...
sasa Posted November 20, 2008 Share Posted November 20, 2008 1st part of code create array $BlockOutput (try to print_r it), and 2nd insert this array in array $BlockArray with index 'Blocks' Quote Link to comment https://forums.phpfreaks.com/topic/133436-solved-array-trouble/#findComment-694524 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.