Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End help with turning a string into array

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36393
    cybershot
    Participant

    I am working in wordpress. I am using a custom field to get an set of values. Right now, it returns this into my theme.

    Pizza, Piatti al forno, Insalata, Toppings, Pagnottelle,

    I tried using explode() to echo it out into an unordered list using the comma as the delimeter but all I could get was

    Array

    or

    Array ( [0] => Array )

    So I set it back to get the values above. Here is what I have right now


    global $wp_query;
    $postid = $wp_query->post->ID;
    $item = get_post_meta($postid, 'lunch menu', true);
    ?>

      foreach( $item as $items){
      echo '
    • '.$items."
    • ";
      }
      wp_reset_query();
      ?>
    #95684
    jamygolden
    Member

    Try this:

    $string = 'Pizza, Piatti al forno, Insalata, Toppings, Pagnottelle';
    $arr = explode(', ', $str);

    for($i = 0; $i < count($arr); $i++) {
    echo '
  • ' .$arr[$i] . "
  • ";
    };
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.