要序列化的数组

时间:2010-10-20 09:49:06

标签: arrays cakephp cakephp-1.3

我有一个像这样的数组

[Cuisine] => Array
        (
            [0] => Array
                (
                    [id] => 3
                    [name] => Arabian 
                    [slug] => 
                    [CuisinesRestaurant] => Array
                        (
                            [id] => 194
                            [restaurant_id] => 1
                            [cuisine_id] => 3
                        )

                )

            [1] => Array
                (
                    [id] => 5
                    [name] => Bengali 
                    [slug] => 
                    [CuisinesRestaurant] => Array
                        (
                            [id] => 195
                            [restaurant_id] => 1
                            [cuisine_id] => 5
                        )

                )

            [2] => Array
                (
                    [id] => 7
                    [name] => Chettinad 
                    [slug] => 
                    [CuisinesRestaurant] => Array
                        (
                            [id] => 196
                            [restaurant_id] => 1
                            [cuisine_id] => 7
                        )

                )

        )

我想创建一个具有每个内部数组名称的行,如下所示

Arabian,Bengali,Chettinad

这是在美食名称之间添加逗号的最佳方法吗?

1 个答案:

答案 0 :(得分:2)

我不确定我的问题是否正确但是这样的话?

$allNames = array();

foreach ($data as $item)
{
    $allNames[] = $item['name'];
}

$data['all_names'] = implode(',', $allNames);

$ data是你的数组。