duanpiyao2734 2017-05-08 14:04
浏览 11
已采纳

计算foreach循环中的数据

I have pulled out data from my database of eps of companies for last 2 years I wanted to sum up eps by using a small formula what happened here is I pulled out data in the form of array now I want to put formula like this `

`

$curr_eps - $old_eps / $old_eps * 100;

With the out put I am getting I am unable to put formula for every company and get separate calculated values

My output data is like this

foreach($data3 as $key => $pr_data) {
            $prof_data[] = $pr_data;
        }
Array
(
    [0] => Array
        (
            [eps] => -0.28
            [year] => 2015
        )

    [1] => Array
        (
            [eps] => 3.33
            [year] => 2014
        )

    [2] => Array
        (
            [eps] => 0.90
            [year] => 2015
        )

    [3] => Array
        (
            [eps] => 0.81
            [year] => 2014
        )

    [4] => Array
        (
            [eps] => 1.05
            [year] => 2016
        )

    [5] => Array
        (
            [eps] => 3.71
            [year] => 2015
        )

    [6] => Array
        (
            [eps] => 1.61
            [year] => 2016
        )

    [7] => Array
        (
            [eps] => -0.49
            [year] => 2015
        )

)

I am wondering to put data here as of without loop this is the output coming on $prof_data[] = $data3 //This contains array value; Out Put`

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [eps] => -0.28
                    [year] => 2015
                    [company_id] => 348
                )

            [1] => Array
                (
                    [eps] => 3.33
                    [year] => 2014
                    [company_id] => 348
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [eps] => 0.90
                    [year] => 2015
                    [company_id] => 351
                )

            [1] => Array
                (
                    [eps] => 0.81
                    [year] => 2014
                    [company_id] => 351
                )

        )

    [2] => Array
        (
            [0] => Array
                (
                    [eps] => 1.05
                    [year] => 2016
                    [company_id] => 356
                )

            [1] => Array
                (
                    [eps] => 3.71
                    [year] => 2015
                    [company_id] => 356
                )

        )

    [3] => Array
        (
            [0] => Array
                (
                    [eps] => 1.61
                    [year] => 2016
                    [company_id] => 366
                )

            [1] => Array
                (
                    [eps] => -0.49
                    [year] => 2015
                    [company_id] => 366
                )

        )

    [4] => Array
        (
        )

)

Now can anybody help me out to solve this issue I am not good while making to understand what I wam trying to do please let e know if you have queries

  • 写回答

1条回答 默认 最新

  • duancenxie2233 2017-05-08 15:07
    关注

    As I understand you can perform calculation as

    foreach($data3 as $data){
       $net = $currenteps - $data['eps'];
    }
    

    You haven't defined what are the currenteps and oldeps, however using $data['eps'] and $data['year'], you can access each eps value and respective year of array

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?