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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.