2
Array 
[1] => Array ( [0] => x [1] => num1 [2] => num2 ) 
[2] => Array ( [0] => y [1] => num3 [2] => num4 ) 
[3] => Array ( [0] => z [1] => num5 [2] => num6 ) 
..........

What I want in php is, [0] index values i.e. x,y,z... become the index and num1, num2... become their values. In short I wanted a hash which has x,y,z... as indexes and num1, num2(for x) num3,num4(for y) as values for those indexes. which should look like,

Array 
[x] => Array ( [0] => num1 [1] => num2 ) 
[y] => Array ( [0] => num3 [1] => num4 ) 
[z] => Array ( [0] => num5 [1] => num6 ) 

1 Answer 1

3

So something like:

$new = Array();
foreach($original as $entry) $new[array_shift($entry)] = $entry;

(Untested, may be buggy with order of operations, but probably fine).

Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot..Its working fine. I am learning programming and php. You guys are really helpful. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.