array_push

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smilesmita
Forum Commoner
Posts: 30
Joined: Thu May 24, 2007 1:52 pm

array_push

Post by smilesmita »

I have an array $attribs which looks like this:

Array ( [] =>
[195] => Brand Marketing Practice [185] => Change Management [902] => Clinical Trial Recruitment [196] => Corporate Practice [176] => Corporate Social Responsibility [177] => Entertainment Marketing [172] => Event and Experimental Marketing [197] => Food & Nutrition Practice [198] => Healthcare Practice [183] => Hispanic Marketing [179] => Influencer Marketing [772] => Interactive Communications [174] => Investor Relations [175] => Issues and Crisis Management [182] => Litigation Communications [186] => Lobbying [1] => Media Relations [171] => Media and Spokesperson Training [184] => Public Affairs [2] => Research [4] => Social Marketing [3] => Sports Marketing [199] => Technology Practice [187] => Women’s Marketing [261] => Word-of-Mouth Marketing )

I want to add another element "employee management" with key=185 ..how would i do this with array_push exactly?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: array_push

Post by John Cartwright »

You can't, array_push is the equivelant to calling

Code: Select all

$foo[] = $bar;
What you can do is,

Code: Select all

$foo[184] = 'employee management';
or

Code: Select all

$attribs = array_merge(array(184 => 'employee management'), $attribs);
Post Reply