Jump to content

Putting all parts of an array into one variable..


Sesquipedalian

Recommended Posts

Hey everyone,

 

What I'm curious of, is how do you put all parts of an array side by side into one variable?

 

What I mean is if you have

array('a', 'b', 'c', 'd')

how do you take it and put it into a variable, so the new variable ends up being

$var = 'abcd';

, where all of the array parts are next to eachother.

 

Appreciate your help!

thanks..

that answered my question.. but i realize it didn't help what i was trying to do.

 

I have a string full of parts that are seperated by |, so something like this:

 

$string = '| This | is | a | part | This | is | a | diff | part';

 

The string updates when i add to it (not manually), and so usually what i do to get the different parts is I use explode.

 

Now what I want to do is make it so that after every 4 array parts (like $string[1], $string[2], $string[3], $string[$4]) it to have a '<br />';

 

so that instead, $string would become 'This is a part <br />This is a diff <br />part'

 

How can I do that?

 

I want it to do it until it gets to the end of the array, so that I can have as much text as I want, and it will just make it like that.

 

I've tried different things, and I'm getting frustrated.. So.. how?

<?php
$parts = array('This','is','a','part','This','is','a','diff','part');

$slices = array();
$lines = ceil(count($parts)/4);
for($i = 0; $i < $lines; $i++)
{
$slices[] = array_slice($parts, $i*4, 4);
}
?>

 

Will split it into slices of up to four. Just join them like above again.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.