Store all array positions in a variable?

Asked

Viewed 804 times

2

I have an array that contains 3 positions, each of them stores a long text, how can I do to store in a single variable all these 3 positions of the array. for example:

Array['Gol', 'Pallium', 'Celtic']

$All over = //All array positions above.

Unfortunately I can’t because my code overwrites until the last position, so the previous positions are lost.

Thanks in advance!

  • Tried as implode ? it will transform all array elements into a string.

1 answer

0


implode(), transforms an array into a string, the function accepts two arguments the first is the delimiter which sepera the array items, the second is the array. If only one argument(array) is entered the output string will be all pasted.

<?php
$arr = Array('Gol','Pálio','Celta', 'Audi A3');
echo $str = implode('#', $arr);
echo $str = implode($arr);

Exit:

Gol#Pálio#Celta#Audi A3
GolPálioCeltaAudi A3

To do the opposite process use the function explode().

Browser other questions tagged

You are not signed in. Login or sign up in order to post.