I have a page set up like Page One, Page Two, Page Three
Each page has a tag of 'content'.
In the Wordpress loop I would like to create an array for each page with the page title as the array name.
I would then like to add and get values from the array using the array name.
I have some demo code here.
If I try to get the length of the array using the array name it returns '0' and the keys/values are not returned.
<?php
$mt_test_args = array(
'post_type' => 'page',
'tag' => 'content',
'order' => 'ASC'
);
$mt_test_loop = new WP_Query($mt_test_args);
if($mt_test_loop->have_posts()):
while($mt_test_loop->have_posts()):
$mt_test_loop->the_post();
// create array for each page
$arr_name = get_the_title();
$arr_name = str_replace(' ','_',$arr_name);
$$arr_name = array();// The page array
// Add text and color keys to array
$$arr_name[$text] = 'Page Text';
$$arr_name[$color] = 'red';
?>
<option><?php the_title(); ?></option>
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>
<?php
print_r($Page_One);
echo count($Page_One); // no echo
echo $Page_One[$text]; // no value
?>