Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5976879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:17:27+00:00 2026-05-22T21:17:27+00:00

I have the following PHP array: $b = array ( 0 =>03xxx, //Index of

  • 0

I have the following PHP array:

$b = array
(
    0 =>"03xxx", //Index of main,  substr(index,0,2)

        1 =>"04xxx",
        2 =>"05xxx",
        //3 =>"06xxx" // missing "06" 
        //4 =>"07xxx",

        6 =>"04xxx",
        7 =>"05xxx",
        8 =>"06xxx",
        //9 =>"07xxx"

    10 =>"08xxx",

    11 =>"03xxx" ,// new index of main

        12 =>"04xxx",
        13 =>"05xxx",
        14 =>"06xxx",

        //15 =>"07xxx" missing "07"
    16 =>"08xxx"
);

I need to transform it to:

/*the expected result 
Array
(
    [0] => Array
        (
            [0] => 03xxx04xxx05xxx          08xxx, // missing 06 ,07
            [1] => 03xxx04xxx05xxx06xxx     08xxx // missing 07 
        )

    [1] => Array
        (
            [0] => 03xxx04xxx05xxx06xxx     08xxx // missing 07
        )

)
*/

Update:

Based on yes123’s answer I arrived at the following solution:

/*
 * thank to @yes123 
*/
function transform($a){
    $result=array();
    $i=0;
    $j=0;
    $last = 2;
    foreach($a as $k=>$v) {
        if (!isset($result[$i]))
            $result[$i]=array('');


        if ( ++$last != $v[1])
            $result[$i][$j] .=  str_repeat(str_pad(" ",5),($v[1]-$last));

        $result[$i][$j] .= $v;

        $last = $v[1];

        if (substr($v,0,2)=='08') {
            $last=3;
            $j++;
        }

        if ($a[$k+1][1]=='3') {
            $last=2;
            $i++;
            $j=0;
        }
    }
    return $result;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:17:28+00:00Added an answer on May 22, 2026 at 9:17 pm

    Watch it live here: http://codepad.org/SWOur3HD version(0.4)

    Here is the source code just in case the link dies:

    <?php
    
    $a = array
    (
        0 =>"03xxx", //Index of main,  substr(index,0,2)
    
        1 =>"04xxx",
        //2 =>"05xxx",
        //3 =>"06xxx" // missing "06" 
        4 =>"07xxx",
        5 =>"08xxx",
    
        6 =>"04xxx",
        7 =>"05xxx",
        8 =>"06xxx",
        //9 =>"07xxx" 
        10 =>"08xxx",
    
        11 =>"03xxx" ,// new index of main
    
        12 =>"04xxx",
        13 =>"05xxx",
        14 =>"06xxx",
        //15 =>"07xxx" missing "07"
        16 =>"08xxx"
    );
    
    
    $result=array();
    $i=0;
    $j=0;
    $last = 2;
    $main='';
    $addMain=false;
    foreach($a as $k=>$v) {
    
      if($v[1]=='3')
        $main=$v;
    
      if (!isset($result[$i]))
        $result[$i]=array('');
    
      if ( ++$last != $v[1])
        $result[$i][$j] .=  str_repeat('     ',($v[1]-$last));
    
      if ($addMain) {
        $result[$i][$j] .= $main;
        $addMain=false;
      }
    
      $result[$i][$j] .= $v;
    
      $last = $v[1];
    
      if ($v[1]=='8') {
        $last=3;
        $j++;
        if ($a[$k+1][1]!='3')
          $addMain=true;
      }
    
      if ($a[$k+1][1]=='3') {
        $last=2;
        $i++;
        $j=0;
        $addMain=false;
      }
    }
    
    print_r($result);
    

    Anyway keep in mind next time you code: Simple is Beautiful (not anymore now lol)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following PHP example code: $client = new SoapClient("http://example.com/example.wsdl"); $h = Array();
I have the following php loop that takes an array that contains a set
I have the following PHP object but I'm struggling to get the array item
I have the following code: <?php $cups = array(); for($i=0; $i<500; $i++){ $cups[$i] =
I am new to PHP. I have a PHP array that is two dimensional.
I have the following code in PHP: $keys = array('a', 'b', 'c'); $data =
I have following code (php), it will match img-src and replace with new url
I have the following php. However when I see the index.php I get the
I have the following url /dir1/dir2/page.php I need to generate a an array of
Say I have the following PHP array: $test = array( 'bob' => array( 'age'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.