Jump to content

Recommended Posts

How can I merge the array, but I keep in mind that I only need to merge userlocation and the usercity arrays.

 

Current output...

 

Array
(
    [0] => Array
        (
            [0] => userlocation
            [1] => 19
        )

    [1] => Array
        (
            [0] => credentials
            [1] => 
        )

    [2] => Array
        (
            [0] => specialties
            [1] => 
        )

    [3] => Array
        (
            [0] => usercity
            [1] => place1
        )

)

 

Desired output...

Array
(
    [0] => Array
        (
            [0] => userlocation
            [1] => 19
            [2] => usercity
            [3] => place1
        )

    [1] => Array
        (
            [0] => credentials
            [1] => 
        )

    [2] => Array
        (
            [0] => specialties
            [1] => 
        )
)

 

How can this be done?  The array is dynamic.

Link to comment
https://forums.phpfreaks.com/topic/236772-array-merge/
Share on other sites

Where are you getting this data from? Where are these arrays?

 

The data is coming from a mysql query. 

 

if (strpos($news['action_id'], '~') !== FALSE)
{
$actions = explode('~', $news['action_id']);
$action_details = explode('~', $news['details']);

$information = array();

foreach ($actions as $k => $action)
{
	$information[] = array($action, $action_details[$k]);
}
}

Link to comment
https://forums.phpfreaks.com/topic/236772-array-merge/#findComment-1217138
Share on other sites

Only guessing but maybe change

		$information[] = array($action, $action_details[$k]);

to

		$information[$action][] = $action_details[$k];

 

If not what is $news['action_id'] and $news['details'] set to?

 

$news['action_id'] is set to something like...

userlocation~credentials~specialties~usercity

 

$news['details'] is set to something like...

19~~~place1

 

That gives me this result which isn't exactly what I want.

 

Array
(
    [userlocation] => Array
        (
            [0] => Array
                (
                    [0] => userlocation
                    [1] => 19
                )

        )

    [credentials] => Array
        (
            [0] => Array
                (
                    [0] => credentials
                    [1] => 
                )

        )

    [specialties] => Array
        (
            [0] => Array
                (
                    [0] => specialties
                    [1] => 
                )

        )

    [usercity] => Array
        (
            [0] => Array
                (
                    [0] => usercity
                    [1] => place1
                )

        )

)

Link to comment
https://forums.phpfreaks.com/topic/236772-array-merge/#findComment-1217161
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.