Title: PHP Question: How to echo an Array
Last modified: August 19, 2016

---

# PHP Question: How to echo an Array

 *  Resolved [kasperbs](https://wordpress.org/support/users/kasperbs/)
 * (@kasperbs)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/php-question-how-to-echo-an-array/)
 * Hi this is probably a very basic question, but here it goes. I’m displaying a
   list of related posts in my single.php and I’m showing the title and the excerpt
   and a custom field image. I would like to cut the length of the excerpt to one
   sentence for each related item.
 * By using preg_split as suggested here:
    [http://php.about.com/od/advancedphp/ss/php_preg_5.htm](http://php.about.com/od/advancedphp/ss/php_preg_5.htm)
 * I have managed to return an array that contains each sentence. I have used this
   code:
 *     ```
       <?php
       $str = $post->post_excerpt;
       $sentances= preg_split('/\./', $str, -1 , PREG_SPLIT_NO_EMPTY);
       print_r($sentances);
       ?>
       ```
   
 * This particular code, returns something like this:
 * > Array ( [0] => Maecenas fermentum semper purus [1] => Fusce vitae tortor [2]
   > => In laoreet ante ornare metus lobortis pretium [3] => Suspendisse eu libero[
   > 4] => Suspendisse facilisis [5] => Phasellus convallis, purus in imperdiet 
   > condimentum, nisi orci gravida ligula, eu pellentesque odio risus quis risus[
   > 6] => Aenean vitae pede at enim imperdiet varius [7] => Vivamus sodales feugiat
   > est [8] => Nulla lobortis consectetuer magna )
 * I would like to only echo the very first sentence, how would i go about doing
   that?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/php-question-how-to-echo-an-array/#post-686103)
 * `echo $sentances[0];`
 *  Thread Starter [kasperbs](https://wordpress.org/support/users/kasperbs/)
 * (@kasperbs)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/php-question-how-to-echo-an-array/#post-686161)
 * EDIT:
    Thanks that worked perfectly.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘PHP Question: How to echo an Array’ is closed to new replies.

## Tags

 * [arrays](https://wordpress.org/support/topic-tag/arrays/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [preg_split](https://wordpress.org/support/topic-tag/preg_split/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [kasperbs](https://wordpress.org/support/users/kasperbs/)
 * Last activity: [18 years, 4 months ago](https://wordpress.org/support/topic/php-question-how-to-echo-an-array/#post-686161)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
