rearrange multidimensional array on basis of value of inner array
Posted
by I Like PHP
on Stack Overflow
See other posts from Stack Overflow
or by I Like PHP
Published on 2010-05-18T10:29:06Z
Indexed on
2010/05/18
10:50 UTC
Read the original article
Hit count: 354
php
|multidimensional-array
i have an array like this
Array
(
[0] => Array
(
[cat_name] => Clothing
[cat_id] => 1
[item_name] => shirt
[item_id] => 1
[src] => 177
[sic] => 78
)
[1] => Array
(
[cat_name] => Stationary
[cat_id] => 3
[item_name] => note book
[item_id] => 8
[src] => 50
[sic] => 10
)
[2] => Array
(
[cat_name] => Stationary
[cat_id] => 3
[item_name] => ball pen
[item_id] => 10
[src] => 59
[sic] => 58
)
[3] => Array
(
[cat_name] => Expandable
[cat_id] => 4
[item_name] => vim powder
[item_id] => 14
[src] => 34
[sic] => 23
)
[4] => Array
(
[cat_name] => Clothing
[cat_id] => 1
[item_name] => pant
[item_id] => 16
[src] => 100
[sic] => 10
)
)
now what i want first it sorted by cat_id and then a create a new array having below structure
Array
(
[0] =>"Clothing"=>Array
(
[0]=>Array
(
[item_name] => shirt
[item_id] => 1
[src] => 177
[sic] => 78
)
[1] => Array
(
[item_name] => pant
[item_id] => 16
[src] => 100
[sic] => 10
)
)
[1] => "Stationary"=>Array
(
[0] => Array
(
[item_name] => note book
[item_id] => 8
[src] => 50
[sic] => 10
)
[1] => Array
(
[item_name] => ball pen
[item_id] => 10
[src] => 59
[sic] => 58
)
)
[2]=>"Expandable => Array
(
[0] => Array
(
[item_name] => vim powder
[item_id] => 14
[src] => 34
[sic] => 23
)
)
)
© Stack Overflow or respective owner