csplrj Posted December 27, 2009 Share Posted December 27, 2009 I want to add a key,value pair to array. I know array_push but it adds only value how to add value alongwith key associated with the same? Something of this sort array_push($array,$key=>$value); Thanks in advance CSJakharia Quote Link to comment https://forums.phpfreaks.com/topic/186403-i-want-to-add-a-keyvalue-pair-to-array/ Share on other sites More sharing options...
cags Posted December 27, 2009 Share Posted December 27, 2009 Is there a reason you can't simply use $arr[$key] = $value? Quote Link to comment https://forums.phpfreaks.com/topic/186403-i-want-to-add-a-keyvalue-pair-to-array/#findComment-984345 Share on other sites More sharing options...
csplrj Posted December 27, 2009 Author Share Posted December 27, 2009 Thanks that will solve my problem. Actually i was so used to array_push that i thought i have to use some sort of function and so asked Thanks CSJakharia Quote Link to comment https://forums.phpfreaks.com/topic/186403-i-want-to-add-a-keyvalue-pair-to-array/#findComment-984354 Share on other sites More sharing options...
cags Posted December 27, 2009 Share Posted December 27, 2009 To add an item to an array without specifying a key you can also use $array[] = $value. Quote Link to comment https://forums.phpfreaks.com/topic/186403-i-want-to-add-a-keyvalue-pair-to-array/#findComment-984476 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.