+88 01797-506292

Post Date: July 19, 2017
Posted By: admin

Custom Array Sorting

$main_array = array(
        'mizan@bitmascot.com', 'Mizanur', 'Rahman', 'Link1',
        'imran@bitmascot.com', 'Imran', 'Khan', 'Link2',
        'hassan@bitmascot.com', 'Hassan', 'Iman', 'Link3',
        'masum@bitmascot.com', 'Masum', 'khan', 'Link4'

    );


    $new_array = array();
    $i=1;
    foreach ($main_array as $key=>$value) {

        if($i==1){
            $tmp_array['email'] = $value;

        }elseif($i==2) {
            $tmp_array['first_name'] = $value;

        }elseif($i==3) {
            $tmp_array['last_name'] = $value;

        }elseif($i==4) {
            $tmp_array['link'] = $value;
        }

        if($i%4==0){
            $new_array[] = $tmp_array;
            $i = 1;
        }else{
            $i++;
        }
    }

    echo '<pre>';
    print_r($new_array);

Leave a Reply

Your email address will not be published. Required fields are marked *