开发者

Add to a multi-dimensional array php

I have an array like this:

$where = array(
 'product_id' => $product_id,
 'item_id' => $item_id
);

I want开发者_StackOverflow社区 to add to this array, based on a condition, so I could do

if($condition){
 $where = array()
}else{
 $where = array()
}

And repeat the original contents twice, but ideally, I'd like to do like an array_push(array('id' => $id), $where);

Thanks!


you may add something to your array in the following way:

$where['mykey'] ='myvalue';


Simply add it to your array by specifying the index and the value.

if($condition){
 $where['id'] = $id;
}else{
 $where['other'] = $other;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜