We use cookies to improve our services and provide a better experience. By continuing to use this site, you agree with our Cookies Policy.

Tutorials

More than 400 step-by-step articles to guide you through online project development.
HomeTutorialsCMS TutorialsWordPressWordPress Administration

How to output comma-separated array

OpenVZ VPS

Whenever we need to get comma-separated array in the output this can be achieved by using simple PHP function. Basically it’s called “explode()” and can be used to return array which is comma-separated.

Here is an example of such code:

1
2
3
4
5
6
7
8
9
$array = get_post_meta($post->ID, 'array', true);
if($array != '') {
$array = explode(',', $array);
if(is_array($array)){
foreach ($array as $array_element) {
echo $array_element;
}
}
}

As we can see function “explode()” is used in this code to return array. The rest of the code makes array elements comma-separated. We may use this code where we want to get array in WordPress website. More information about “explode()” usage can be found by visiting official PHP manual.

Brazil VPS
Rate this Tutorial:
No Comments Leave a Comment
Leave a Comment

Other (182)

Popular Keywords