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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.