dongtao1262 2015-05-21 16:12
浏览 110

从数组/字符串中获取值

How can I fetch the value "3" from this set of arrays:

array(1) { [0]=> string(1) "1" }
array(1) { [0]=> string(1) "3" }
array(1) { [0]=> string(1) "0" } 

The arrays are output from a foreach statement of parenting array, which is:

array(3) { [0]=> string(8) "St" [1]=> string(1) "1" [2]=> string(1) "0" }
array(3) { [0]=> string(16) "Fu" [1]=> string(1) "3" [2]=> string(1) "0" }
array(3) { [0]=> string(13) "Pa" [1]=> string(1) "0" [2]=> string(1) "0" } 

Where I am going for the second line value: "Fu" [1]=> string(1) "3"

Maybe I am doing it wrong from the first array?

  • 写回答

1条回答 默认 最新

  • donglang1976 2015-05-21 16:23
    关注

    You're not giving us much to go on. Are the 3 arrays already in a parent array, in an object, etc.? Below is how to get the # 3 from the 3 arrays...but I'm guessing this is not actually what you are asking, we likely need much more detail...the real problem you are trying to solve.

    function getThree($arr1, $arr2, $arr3) {
        $array = array();
        $array[] = $arr1;
        $array[] = $arr2;
        $array[] = $arr3;
    
        foreach( $array AS $subArray ) {
            // whichever condition works for you
            if( $subArray[0] == 'Fu' || $subArray[1] == 3 ) {
                return $subArray;
            }
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?