Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.