MyPage is a personalized page based on your interests.The page is customized to help you to find content that matters you the most.


I'm not curious

How to split/divide an array into 2 using php ?

0
Started on: 02 January 13
Participants: 1

Hi Guys,

Help me to split or divide an array into 2 different arrays

my single array

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

i want the above array into two array like below

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

Hi Guys,

Help me to split or divide an array into 2 different arrays

my single array

$array = array("1","2","3","4","5","6"); i want the above array into two array like below

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

This challenge is listed under Open Source and Development & Implementations Community

Related Posts:

PHP

 

Initiator

Aravinthan
Aravinthan
  Follow

I am passinate about IT & PHP , Let's do it

More posts by: Aravinthan Asokan

1 Suggestion

  1. 02 January 13
    0



    Hi InnoThink, Try following solution, <?php $ar = array("1","2","3","4","5","6"); $ar_new = array_chunk($ar, ceil(count($ar)/2)); $ar1 = $ar_new[0]; $ar2 = $ar_new[1]; echo '<pre>'; print_r($ar1); print_r($ar2); /* ### Output Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 4 [1] => 5 [2] => 6 ) */

Awards & Accolades for MyTechLogy
Winner of
REDHERRING
Top 100 Asia
Finalist at SiTF Awards 2014 under the category Best Social & Community Product
Finalist at HR Vendor of the Year 2015 Awards under the category Best Learning Management System
Finalist at HR Vendor of the Year 2015 Awards under the category Best Talent Management Software
Hidden Image Url

Back to Top