dongli8466 2017-09-11 03:55
浏览 47

如何在php中将值分别显示为字符串,整数和双精度

How can I display the value separate into string, integer and double in PHP using multidimensional array?

Here's my code:

<?php
$array = array(
    array ("one"=>1,"two"=>"two","three"=>3.1,"four"=>4,"five"=>"five"),
    array ("six"=>6.1,"seven"=>7,"eight"=>"eight","nine"=>9.1,"ten"=>10),
    array ("eleven"=>"eleven","twelve"=>12.1,"thirteen"=>13,"fourteen"=>"fourteen","fifteen"=>15.1),
    array ("sixteen"=>16,"seventeen"=>"seventeen","eighteen"=>18.1,"nineteen"=> 19,"twenty"=>"twenty"),
    array ("twenty-one"=>21.1,"twenty-two"=>22,"twenty-three"=>"twenty-three","twenty-four"=>24.1,"twenty-five"=>25)
);
  • 写回答

2条回答 默认 最新

  • douke6881 2017-09-11 04:25
    关注

    Use two foreach statement, one to get each array and one to loop get the value and use switch/case to determine the value and according to it add this value to the array of that type

    $integer=array();
    $double=array();
    $string=array()
    foreach ($rows as $row) {
    foreach($row as $key=>$value){
    switch (true){
        case is_string($value):
            // string
    $string[]=$value;
            break;
        case is_int($value):
            // int
    $integer[]=$value;
            break;
        case is_float($value);
           // double 
    $double[]=$value;
           break;
    default:
    }
    }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请提供一个符合要求的网页链接。
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码