开发者

Add to a multi-dimensional array php

开发者 https://www.devze.com 2023-03-12 01:00 出处:网络
I have an array like this: $where = array( \'product_id\' => $product_id, \'item_id\' => $item_id

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

精彩评论

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