0
if ( count($value) >= 3 ) {
    echo '<pre>'.print_r( array_slice($value, 0, -1) ,1).'</pre>';
    echo '<pre>'.print_r( array_slice($value, -1) ,1).'</pre>';
}

... it prints the values as I expect, but I'm not sure how to convert it to a string so for example:

Array
(
    [0] => Dr.
    [1] => John
    [2] => Appleseed
)
Array
(
    [0] => Jr
)

becomes:

Array
(
    [0] => Dr. John Appleseed
)
Array
(
    [0] => Jr
)
2
  • Or join($value). Commented Jul 4, 2015 at 18:08
  • Give a try to implode(" ", $array); Commented Jul 4, 2015 at 18:09

1 Answer 1

1

You can use implode()

<?php

$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);

echo $comma_separated; // lastname,email,phone

// Empty string when using an empty array:
var_dump(implode('hello', array())); // string(0) ""

?>

Specific code

<?php

    echo '<pre>' . implode($value) . '</pre>'; // Dr. John Appleseed
    echo '<pre>' . $value[0] . '</pre>'; // Jr
Sign up to request clarification or add additional context in comments.

1 Comment

You can simply use implode($value) instead

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.