search

Home  >  Q&A  >  body text

javascript - How to turn an array into a negative number in php

1. I have an array array(1,2,3); I need it to become a negative number when inserting it into the database

2. The front-end input table displays a positive number, and the back-end becomes a negative number before inserting it into the database. How to achieve this?

欧阳克欧阳克2812 days ago907

reply all(3)I'll reply

  • 黄舟

    黄舟2017-06-12 09:24:42

    $arr1 = array(1,2,3);
    $arr2 = array();
    foreach($arr1 as $v){

      $arr2[] = -$v;
    

    }

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-12 09:24:42

    $a = array(1, 2, 3, 4, 5);
    $a = array_map(function ($item) {
        return $item<0?$item:-$item;
    }, $a);

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-12 09:24:42

    Loop, take negative value and save to database

    reply
    0
  • Cancelreply