Get array's columns index and merge them into a single dimen

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
greg7
Forum Commoner
Posts: 32
Joined: Tue Oct 13, 2009 7:38 am

Get array's columns index and merge them into a single dimen

Post by greg7 »

Hi guys, i have to do something for today but i'm too excausted so i post for some help, i have an array with 2 dimensions, all i need is to gather the number of column that contains 1 and insert them into one dimensional array. I tried with array_merge() , array_combine and array_fill but i can't find a solution right now.

Assuming the following array1(3x3)

Code: Select all

[color=#FF0000]  0 1 2[/color]
[color=#FF0040]0[/color] 0 0 1
[color=#FF0040]1 [/color]1 1 0
[color=#FF0040]2[/color] 0 1 1
 
I want to create single dimension array2, which will hold the index of the column that contains 1
[color=#FF0040][0][/color]=>  2
[color=#FF0040][1][/color]=>  0, 1   //No of cols, of array1, all in one cell with commas
[color=#FF0040][2][/color]=>  1, 2
 
Thanks in advance for your time reading it!
Last edited by greg7 on Thu Jan 14, 2010 11:03 am, edited 2 times in total.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Get array's columns index and merge them into a single dimen

Post by AbraCadaver »

It would be easier to help and see what you're doing if you use a more familiar syntax:

Code: Select all

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => 0
                )
        )
    [1] => Array
        (
            [0] => Array
                (
                    [0] => 1
                )
        )
)
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
greg7
Forum Commoner
Posts: 32
Joined: Tue Oct 13, 2009 7:38 am

Re: Get array's columns index and merge them into a single dimen

Post by greg7 »

Thanks for your reply, i think i found the solution, i'm totally idiot. If a cell contains 1, i will save column's index into a string and then i save it into the new single dimension array.
Post Reply