Jump to content

How can i make two array slicing an array?


colap

Recommended Posts

Given array

Array
(
    [Post] => Array
        (
            [title] => new with has many through for tags
            [body] => hello tags
            [category_id] => 11
            [tags] => one two three
            [mark] => 1
        )

)

 

I need to make an array something like this:

Array
(
[Post] => Array
        (
            [title] => new with has many through for tags
            [body] => hello tags
            [category_id] => 11        
            [mark] => 1
        )
[Tag] => Array
        (
       		[0] => Array( [name] => one )
       		[1] => Array( [name] => two )
       		[2] => Array( [name] => three )
        )
)

 

How can i make it?

Is it an array with just one record or would you have multiple "POSTS" in the array? If you have multiple posts, the output format will not work - or, at least, you need to show an example of what you want for a mufti-record output because it doesn't make sense to me.

 

Plus, why would you want to make the tags elements separate subarrays with only one element. That really makes no sese. I can see making the tags a subarray, but not with each one as a single element array.

 

I was going to provide a solution, but after looking at what you are really asking for I would rather see "why" you think you need that. I think we can probably provide a better solution for processing the data than what you may be doing now.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.