Jump to content

ttmt_101

Members
  • Posts

    10
  • Joined

  • Last visited

ttmt_101's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. cpd - I know this isn't OOP in the slightest but I needed a named container, I thought i was going to include other things in it. I think now i only need the select menu so it would work in a variable - I've made this so complicated for myself.
  2. @web_craftsman: I'm trying to create a named container I can reference later in the code to hold a select menu. All this object will do is hold a reference to the select menu. Is there another way of doing this?
  3. @web_craftsman: what encapsulation issues?
  4. Hi all This is following on from my previous questions. I'm creating an <select> menu from an array and adding it to a variable I'm also creating an Object. How can I add the select menu variable to the Object. This is all because I just need a named container to hold the select menu. <?php class Color{ var $select; } $col_Arr = array('Red','Green','Blue'); $select_menu = "<select>"; for($i=0; $i<count($col_Arr); $i++){ $select_menu .="<option>".$col_Arr[$i]."</option>"; } echo "</select>"; $My_Col = new Color; //How do I add $select_menu to $My_Col $My_Col->$select = $select_menu; $My_Col->$select_menu; ?>
  5. Thanks Still alive I've been doing '+=' for the last 30 mins instead of '.='
  6. Hi all I want to create a simple html select menu from an array like: <select> <option value="">Red</option> <option value="">Green</option> <option value="">Blue</option> </select> I know I can output this like: $my_Arr = array('Red','Green','Blue'); echo "<select>"; for($i=0; $i<count($my_Arr); $i++){ echo"<option>".$my_Arr[$i]."</option>"; } echo "</select>"; But I would like to add the select menu to a variable and use later. So I can start the variable off like: $select_menu = "<select>"; But how can I add the rest of the html code to the variable as it's created, so I end up with: $select_menu = "<select> <option value="">Red</option> <option value="">Green</option> <option value="">Blue</option> </select>"
  7. so my example should be class Car{ var car_list = array(); } $cars = array('ford','nissan','renault'); $my_car = new Car; array_push($my_car->car_list,$cars)
  8. Hi all Is it possible to create an array in an object and then add an array to that array Something like this. This is completely nonsense code, I'm just trying to illustrate my question. class Car{ var $car_list = array(); } $cars = array('ford','nissan','renault'); $my_car = new Car; array_push($my_car->$car_list,$cars)
  9. Sorry, $text and $font_size is a typo, text and font_size were just examples of content i might add to the array, I'm not apply to edit the original post now. I want to use dynamic variables so I can l reference the arrays later in my code. If there are 3 pages and 3 arrays are created how do I reference the correct array. I used str_replace() because the page titles have spaces and I didn't think i could have space in an array name.
  10. Hi all I'm using Wordpress, I have three simple pages with the titles - Page One, Page Two, Page Three Each page has a tag of 'content'. For each page I would like to create an array with a name the same as that page so Page_One[], Page_Two[] etc. I would like to then add and retrieve vales from this array. In the example here the is_Array echo says it's and array. The print_r and count show the array is empty. Is it possible to create an associative array and name it dynamically here, then add and retrieve values. <?php $mt_test_args = array( 'post_type' => 'page', 'tag' => 'font', '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(); $weight = get_post_meta($post->ID,'weight',false); // create array for each font $arr_name = get_the_title(); $arr_name = str_replace(' ','_',$arr_name); ${$arr_name} = array();// The font array echo is_Array($$arr_name) ? 'yes' : 'no'; // Add text and font size keys to array $$arr_name[$text] = 'first text'; $$arr_name[$font_size] = '2'; ?> <option><?php the_title(); ?></option> <?php endwhile; endif; ?> <?php wp_reset_postdata(); ?> <?php print_r($Alber_New); echo count($Alber_New); echo $Alber_New[$text]; ?>
×
×
  • 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.