# How do I split them?

Hi,
I have an array var which contains 6 values. I want to split this array var into two vars which each of the two holds three values. Example:

\$x = array (
("1"."2"."3"."4","5","6");

And I want to split it into two vars like this:

\$z = 123
\$s = 456

Any help would be highly appreciated in advance
Hakeem
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Like this?

\$z = \$x[1] . \$x[2] . \$x[3];
\$s = \$x[4] . \$x[5] . \$x[6];
0
Commented:
actually, it may start from 0 and not one, so:

\$z = \$x[0] . \$x[1] . \$x[2];
\$s = \$x[3] . \$x[4] . \$x[5];

That would result in:

\$z = 123
\$s = 456
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

LAMP DeveloperCommented:
i think you can use array_slice()  function to slice and make those variables,

<?php
\$x = array (("1"."2"."3"."4","5","6");

\$z = array_slice(\$input, 2);
\$s = array_slice(\$input, -2, 3);

?>

just try with this
0
Commented:
try this

\$z = substr(implode(",", \$array),1,strlen(implode(",", \$array))/2);
\$s = substr(implode(",", \$array),strlen(implode(",", \$array))/2+1);
0
Author Commented:
This gave me the first,second,third...etc of the first word.
0
LAMP DeveloperCommented:
\$x = array (("1"."2"."3"."4","5","6");

Is this structure correct??
0
Commented:
Should be:
\$x = array ("1"."2"."3"."4","5","6");

Surely?
0
LAMP DeveloperCommented:
i hope it might be,

\$x = array ("1","2","3","4","5","6");

then everything works well.,
0
Commented:
\$x = array("1","2","3","4","5","6");

\$z = implode("", array_slice(\$x,0,3));
\$s = implode("", array_slice(\$x,3));
0
Commented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
Split: Phatzer {http:#20804600} & logudotcom {http:#20804614} & netmunky {http:#20805442}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

cyberwebservice
Experts Exchange Cleanup Volunteer
0
Commented:
Forced accept.

Computer101