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 8775751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:52:59+00:00 2026-06-13T18:52:59+00:00

how to get all word in first index in array below and next index

  • 0

how to get all word in first index in array below and next index get???
last word in array 2 D,.. example:

$arr = array( 
  array( 
    '3'=>'repsol kawasaki honda ktm', 
    '4'=>'kawasaki honda ktm bmw', 
    '5'=>'honda ktm bmw ducati', 
    '6'=>'ktm bmw ducati yamaha'
  ) , 
  array( 
    '13'=>'lamborghi ferarri mercedes hyundai', 
    '14'=>'ferarri mercedes hyundai toyota',
    '15'=>'mercedes hyundai toyota nissan',
    '16'=>'hyundai toyota nissan renault'
  ), 
);

I want yield like this:

   Array ( 
     [0] => Array (
       [0] => repsol kawasaki honda ktm 
       [1] => bmw 
       [2] => ducati
       [3] => yamaha 
      ) 
     [1] => Array ( 
       [13] => lamborghi ferarri mercedes hyundai 
       [14] => toyota 
       [15] => nissan  
       [16] => renault 
       ) 
   )
  • 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-06-13T18:53:00+00:00Added an answer on June 13, 2026 at 6:53 pm

    This should do what you want…

    function parseArray( &$arr ){
      $out = array();
      $keys = array_keys( $arr );
      $out[ $keys[0] ] = $arr[$keys[0]];
      unset($arr[$keys[0]]);
      foreach( $arr as $key => $val ){
        $out[ $key ] = array_pop( explode(' ', $val ) );
      }
      $arr = $out;
    }
    

    Then use array_walk to apply the function to each inner array like this

    $data = array(
      array(
        '3'=>'repsol kawasaki honda ktm', 
        '4'=>'kawasaki honda ktm bmw',   
        '5'=>'honda ktm bmw ducati', 
        '6'=>'ktm bmw ducati yamaha'
      ),
      array(
        '13'=>'lamborghi ferarri mercedes hyundai',
        '14'=>'ferarri mercedes hyundai toyota',
        '15'=>'mercedes hyundai toyota nissan',
        '16'=>'hyundai toyota nissan renault'
      )
    );
    
    echo "Before:\n";
    print_r($data);
    // Walk our array
    array_walk( $data, 'parseArray');
    
    echo "After\n";
    print_r($data);
    

    Output

    Before:
    Array
    (
        [0] => Array
            (
                [3] => repsol kawasaki honda ktm
                [4] => kawasaki honda ktm bmw
                [5] => honda ktm bmw ducati
                [6] => ktm bmw ducati yamaha
            )
    
        [1] => Array
            (
                [13] => lamborghi ferarri mercedes hyundai
                [14] => ferarri mercedes hyundai toyota
                [15] => mercedes hyundai toyota nissan
                [16] => hyundai toyota nissan renault
            )
    
    )
    
    After:    
    Array
    (
        [0] => Array
            (
                [3] => repsol kawasaki honda ktm
                [4] => bmw
                [5] => ducati
                [6] => yamaha
            )
    
        [1] => Array
            (
                [13] => lamborghi ferarri mercedes hyundai
                [14] => toyota
                [15] => nissan
                [16] => renault
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to get all id of div.A that has div.collapse is visible,example: <div class=A>
The following query will get all public posts about the word invested. https:graph.facebook.com/search?q=invested&type=post&fields=id,type,message however,
Hello Im trying to get all possible combinations with repetitions of given char array.
I'm trying to make a code which will get first words from all lines
Okay so here is what I'm trying to accomplish. First of all below table
Can get all triples with value null in specific field? All people with date_of_birth
To get all contacts I'm using ABAddressBookCopyArrayOfAllPeople method but, this method return all contacts
I am trying to get all Books from the server (local PHP script), that
I'm trying to get all downloads from an repo on github with help of
How can i get all child nodes from sql table? (MemberJoiners table on pict)

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.