Jump to content

Array Merge?


unemployment

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

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.