Jump to content

[SOLVED] Array Trouble


Styles2304

Recommended Posts

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

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

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

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

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

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.