Link to home
Start Free TrialLog in
Avatar of Victor Kimura
Victor KimuraFlag for Canada

asked on

PHP push array using array_push() to same array

Hi,

I have this bit of code:

$fields = array(
    //set for all selections
    'METHOD' => $METHOD,
    'VERSION' => $VERSION,
    'USER' => $USER,
    'PWD' => $PWD,
    'SIGNATURE' => $SIGNATURE,
    'BUTTONCODE' => $BUTTONCODE,
    'BUTTONSUBTYPE' => $BUTTONSUBTYPE,
    'L_BUTTONVAR1' => $L_BUTTONVAR1,
    'OPTION0NAME' => $OPTION0NAME
);


$aFieldsAppend = array (
    //set in 3, 6, 12,
    'L_BUTTONVAR2' => $L_BUTTONVAR2,
    'BUTTONTYPE' => $BUTTONTYPE,
    'L_OPTION0SELECT0' => $L_OPTION0SELECT0,
    'OPTION0TYPE' => $OPTION0TYPE
);
array_push($fields, $aFieldsAppend);

Open in new window


I'm trying to use the array_push() and push another array with key=>value to the same array but when I use it the second array $aFeildsAppend it's pushed to $fields[0] rather than just $fields.

I tried this code too but it doesn't work:

array_push($fields, ('L_BUTTONVAR2' => $L_BUTTONVAR2,
    'BUTTONTYPE' => $BUTTONTYPE,
    'L_OPTION0SELECT0' => $L_OPTION0SELECT0,
    'OPTION0TYPE' => $OPTION0TYPE));

Open in new window


How can I push the second array to the first one properly so it's all on the same array?

Thanks,
Victor
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Victor Kimura

ASKER

@Cathal Yes, that's right.

Thanks @acbxyz. I didn't think of that solution. Simple.

But I found that I could do this too:

$fields = array_merge($fields, $aFieldsAppend);

Open in new window

I've requested that this question be closed as follows:

Accepted answer: 500 points for acbxyz's comment #a39828275
Assisted answer: 0 points for vkimura2007's comment #a39828306

for the following reason:

found a solution using array_merge() too.  =)
Ermm did you miss the link in my comment.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Cathal, Oh, so sorry! I did miss it! Sorry. =( Can I award half the points to you still? Will try. Sorry, Cathal.