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
ShopiesAsked:
Who is Participating?
 
PhatzerConnect With a Mentor 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
 
PhatzerCommented:
Like this?

$z = $x[1] . $x[2] . $x[3];
$s = $x[4] . $x[5] . $x[6];
0
 
Loganathan NatarajanConnect With a Mentor 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ee_rleeCommented:
try this

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

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

Surely?
0
 
Loganathan NatarajanLAMP DeveloperCommented:
i hope it might be,

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

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

$z = implode("", array_slice($x,0,3));
$s = implode("", array_slice($x,3));
0
 
CWS (haripriya)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
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
All Courses

From novice to tech pro — start learning today.