Jump to: navigation, search

PHP Array Convert to String

From w3cyberlearnings

Contents

PHP Turns Array To String

Turn array to string.

Example 1: Use join() function

<?php

$actor = array(
	 'Greta Garbo',
	 'Andy Garcia',
	 'Ava Gardner',
	 'Lucy Johnson'
);

$str_actor = join(', ', $actor);
echo $str_actor;
?>

Output

Greta Garbo, Andy Garcia, Ava Gardner, Lucy Johnson

Example 2

The array_map() function converts array to all upper case letter.

<?php

$actor = array(
	 'Greta Garbo',
	 'Andy Garcia',
	 'Ava Gardner',
	 'Lucy Johnson'
);

$actor = array_map('strtoupper', $actor);
$str_actor = join(', ', $actor);
echo $str_actor;
?>

Output

GRETA GARBO, ANDY GARCIA, AVA GARDNER, LUCY JOHNSON

Related Links


--PHP Array Introduction-- PHP Access Array-- PHP Array Convert to Object-- PHP Array Convert to JSON-- PHP Array Convert to Class-- PHP Array Convert to String--

Navigation
Web
SQL
MISC
References