简体   繁体   中英

How to append array key and value into another array

I'm trying to push a new array key and value into the exiting array. Therefore, I use array_push to append the data.

Code

$account_no = $acc_no['bank']['account_no'];
$new_account_no = [
                    $model->id => Input::get('account_no'),//This result is "32" => "1234562"
                  ];
array_push($account_no, $new_account_no);

Result

"bank": {
      "account_no": {
        "23": "1111111111",
        "24": {
          "32": "1234562"
        }
      }
    }

So now the problem is, the array data I pushed added a key 24 which is incorrect and it suppose only push "32": "1234562"

Expected result

"bank": {
          "account_no": {
            "23": "1111111111",
            "32": "1234562" 
          }
        }

$account_no[$model->id] = Input::get('account_no');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM