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? 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. 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? 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??? 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? 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? 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 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++; } ?> 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); ?> 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? 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' Link to comment https://forums.phpfreaks.com/topic/133436-solved-array-trouble/#findComment-694524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.