cakephp – Array to Serialize – Education Career Blog

i have an array like this

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
                        )

                )

        )

i wanna create a row with the name of each inner array like this

Arabian, Bengali, Chettinad

which is the best way to add a comma in between the cuisine names ?

,

Not sure i understand your question correct but something like this?

$allNames = array();

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

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

Where $data is your array.

Leave a Comment