Jump to content

Recommended Posts

Hello,

 

I am just trying to work out how replace the contents of the following array:

 

Array

(

    [0] => Array

        (

        )

 

    [1] => Array

        (

            [0] => 18

            [1] => 7

            [2] => 5

            [3] => 4

        )

 

    [2] => Array

        (

            [0] => 48

            [1] => 7

        )

 

    [3] => Array

        (

            [0] => 7

            [1] => 5

            [2] => 4

        )

 

    [4] => Array

        (

            [0] => 48

            [1] => 18

            [2] => 7

            [3] => 5

            [4] => 4

        )

 

)

 

With a new array which replaces the sub array items with one item that is equal to the count of each sub array.. does that make sense? so the resulting array in this case would look like:

 

Array

(

    [0] => Array

        (

 

        )

 

    [1] => Array

        (

            [0] => 4

        )

 

    [2] => Array

        (

            [0] => 2

        )

 

    [3] => Array

        (

            [0] => 3

        )

 

    [4] => Array

        (

            [0] => 5

       

        )

 

)

Link to comment
https://forums.phpfreaks.com/topic/191595-altering-an-array/
Share on other sites

Sorry for the nonsensicalness. I was rushing earlier.

 

Here goes again:

 

I have an array which contains a subset of arrays:

Array(    
    [0]=> Array(
                                         )
    [103] => Array(           
                          [0]=> 18
                          [1] => 7
                          [2] => 5
                          [3] => 4
                                         )
    [112] => Array (
                          [0] => 48
                          [1] => 7
                                         )
    [123] => Array (
                          [0] => 7
                          [1] => 5
                          [2] => 4
                                       )
    [140] => Array (
                          [0]=> 48
                          [1] => 18
                          [2] => 7
                          [3] => 5
                          [4] => 4
                                        )
)

What I am trying to is create another array which is derived from this. The subset arrays of the new array would contain just one entry which reflects the count of the original arrays subset counterpart. So the new array would look like this:

Array(    
    [100]=> Array(
                                         )
    [103] => Array(           
                          [0]=> 4
                                       )
    [112] => Array (
                          [0] => 2
                                       )
    [123] => Array (
                          [0] => 3
                                       )
    [140] => Array (
                          [0]=> 5
                                       )
)

Thanks for the reply teamatomic, I am just working through your suggestion now.

 

Spencer

Link to comment
https://forums.phpfreaks.com/topic/191595-altering-an-array/#findComment-1009990
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.